diff --git a/src/ParallelTestRunner.jl b/src/ParallelTestRunner.jl index 6f00a58..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 = 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) @@ -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 + # Create a new binding instead of assigning to the existing one to avoid `p` 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)