From 45110e35c5f771a37c7d5d512a887411e9cec2ab Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Sun, 1 Mar 2026 17:11:29 +0400 Subject: [PATCH 1/3] Slightly improve inferred types in `runtests` --- src/ParallelTestRunner.jl | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/ParallelTestRunner.jl b/src/ParallelTestRunner.jl index 6f00a58..c0200c3 100644 --- a/src/ParallelTestRunner.jl +++ b/src/ParallelTestRunner.jl @@ -788,7 +788,7 @@ function runtests(mod::Module, args::ParsedArgs; # determine parallelism jobs = something(args.jobs, default_njobs()) - jobs = clamp(jobs, 1, length(tests)) + jobs::Int = clamp(jobs, 1, length(tests)) 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.") nworkers = min(jobs, length(tests)) workers = fill(nothing, nworkers) @@ -798,10 +798,10 @@ function runtests(mod::Module, args::ParsedArgs; running_tests = Dict{String, Float64}() # test => start_time test_lock = ReentrantLock() # to protect crucial access to tests and running_tests - done = false + done = Ref(false) function stop_work() - if !done - done = true + if !done[] + done[] = true for task in worker_tasks task == current_task() && continue Base.istaskdone(task) && continue @@ -950,7 +950,7 @@ function runtests(mod::Module, args::ParsedArgs; end # After a while, display a status line - if !done && time() - t0 >= 5 && (got_message || (time() - last_status_update[] >= 1)) + if !done[] && time() - t0 >= 5 && (got_message || (time() - last_status_update[] >= 1)) update_status() last_status_update[] = time() end @@ -983,7 +983,7 @@ function runtests(mod::Module, args::ParsedArgs; worker_tasks = Task[] for p in workers push!(worker_tasks, @async begin - while !done + while !done[] # get a test to run test, test_t0 = Base.@lock test_lock begin isempty(tests) && break @@ -1001,12 +1001,14 @@ function runtests(mod::Module, args::ParsedArgs; else test_worker(test, init_worker_code) end + # Use a copy of p to prevent it from being boxed + p2 = p if wrkr === nothing - wrkr = p + wrkr = p2 end # if a worker failed, spawn a new one if wrkr === nothing || !Malt.isrunning(wrkr) - wrkr = p = addworker(; init_worker_code, io_ctx.color) + wrkr = p2 = addworker(; init_worker_code, io_ctx.color) end # run the test @@ -1055,7 +1057,7 @@ function runtests(mod::Module, args::ParsedArgs; end # get rid of the custom worker - if wrkr != p + if wrkr != p2 Malt.stop(wrkr) end @@ -1075,7 +1077,7 @@ function runtests(mod::Module, args::ParsedArgs; if any(istaskfailed, worker_tasks) println(io_ctx.stderr, "\nCaught an error, stopping...") break - elseif done || Base.@lock(test_lock, isempty(tests) && isempty(running_tests)) + elseif done[] || Base.@lock(test_lock, isempty(tests) && isempty(running_tests)) break end sleep(1) From 07d1c4d13efa94f770bee9be95cf59f6d640d337 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Sun, 1 Mar 2026 18:17:50 +0400 Subject: [PATCH 2/3] Update comment --- src/ParallelTestRunner.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ParallelTestRunner.jl b/src/ParallelTestRunner.jl index c0200c3..5276f49 100644 --- a/src/ParallelTestRunner.jl +++ b/src/ParallelTestRunner.jl @@ -1001,7 +1001,7 @@ function runtests(mod::Module, args::ParsedArgs; else test_worker(test, init_worker_code) end - # Use a copy of p to prevent it from being boxed + # Create a new binding instead of assigning to the existing one to avoid `p` from being boxed p2 = p if wrkr === nothing wrkr = p2 From a0bd543f1470aba0482479f8a3bb084a3e35d4f2 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Sun, 1 Mar 2026 18:19:34 +0400 Subject: [PATCH 3/3] Rename the first `jobs` to `_jobs` --- src/ParallelTestRunner.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ParallelTestRunner.jl b/src/ParallelTestRunner.jl index 5276f49..4345e6f 100644 --- a/src/ParallelTestRunner.jl +++ b/src/ParallelTestRunner.jl @@ -787,8 +787,8 @@ function runtests(mod::Module, args::ParsedArgs; sort!(tests, by = x -> -get(historical_durations, x, Inf)) # determine parallelism - jobs = something(args.jobs, default_njobs()) - jobs::Int = clamp(jobs, 1, length(tests)) + _jobs = something(args.jobs, default_njobs()) + jobs::Int = clamp(_jobs, 1, length(tests)) 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.") nworkers = min(jobs, length(tests)) workers = fill(nothing, nworkers)