Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/ParallelTestRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down