Skip to content

Commit 16f47d4

Browse files
authored
Slightly improve inferred types in runtests (#100)
* Slightly improve inferred types in `runtests` * Update comment * Rename the first `jobs` to `_jobs`
1 parent bfdd716 commit 16f47d4

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

src/ParallelTestRunner.jl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,8 @@ function runtests(mod::Module, args::ParsedArgs;
787787
sort!(tests, by = x -> -get(historical_durations, x, Inf))
788788

789789
# determine parallelism
790-
jobs = something(args.jobs, default_njobs())
791-
jobs = clamp(jobs, 1, length(tests))
790+
_jobs = something(args.jobs, default_njobs())
791+
jobs::Int = clamp(_jobs, 1, length(tests))
792792
println(stdout, "Running $jobs tests in parallel. If this is too many, specify the `--jobs=N` argument to the tests, or set the `JULIA_CPU_THREADS` environment variable.")
793793
nworkers = min(jobs, length(tests))
794794
workers = fill(nothing, nworkers)
@@ -798,10 +798,10 @@ function runtests(mod::Module, args::ParsedArgs;
798798
running_tests = Dict{String, Float64}() # test => start_time
799799
test_lock = ReentrantLock() # to protect crucial access to tests and running_tests
800800

801-
done = false
801+
done = Ref(false)
802802
function stop_work()
803-
if !done
804-
done = true
803+
if !done[]
804+
done[] = true
805805
for task in worker_tasks
806806
task == current_task() && continue
807807
Base.istaskdone(task) && continue
@@ -950,7 +950,7 @@ function runtests(mod::Module, args::ParsedArgs;
950950
end
951951

952952
# After a while, display a status line
953-
if !done && time() - t0 >= 5 && (got_message || (time() - last_status_update[] >= 1))
953+
if !done[] && time() - t0 >= 5 && (got_message || (time() - last_status_update[] >= 1))
954954
update_status()
955955
last_status_update[] = time()
956956
end
@@ -983,7 +983,7 @@ function runtests(mod::Module, args::ParsedArgs;
983983
worker_tasks = Task[]
984984
for p in workers
985985
push!(worker_tasks, @async begin
986-
while !done
986+
while !done[]
987987
# get a test to run
988988
test, test_t0 = Base.@lock test_lock begin
989989
isempty(tests) && break
@@ -1001,12 +1001,14 @@ function runtests(mod::Module, args::ParsedArgs;
10011001
else
10021002
test_worker(test, init_worker_code)
10031003
end
1004+
# Create a new binding instead of assigning to the existing one to avoid `p` from being boxed
1005+
p2 = p
10041006
if wrkr === nothing
1005-
wrkr = p
1007+
wrkr = p2
10061008
end
10071009
# if a worker failed, spawn a new one
10081010
if wrkr === nothing || !Malt.isrunning(wrkr)
1009-
wrkr = p = addworker(; init_worker_code, io_ctx.color)
1011+
wrkr = p2 = addworker(; init_worker_code, io_ctx.color)
10101012
end
10111013

10121014
# run the test
@@ -1055,7 +1057,7 @@ function runtests(mod::Module, args::ParsedArgs;
10551057
end
10561058

10571059
# get rid of the custom worker
1058-
if wrkr != p
1060+
if wrkr != p2
10591061
Malt.stop(wrkr)
10601062
end
10611063

@@ -1075,7 +1077,7 @@ function runtests(mod::Module, args::ParsedArgs;
10751077
if any(istaskfailed, worker_tasks)
10761078
println(io_ctx.stderr, "\nCaught an error, stopping...")
10771079
break
1078-
elseif done || Base.@lock(test_lock, isempty(tests) && isempty(running_tests))
1080+
elseif done[] || Base.@lock(test_lock, isempty(tests) && isempty(running_tests))
10791081
break
10801082
end
10811083
sleep(1)

0 commit comments

Comments
 (0)