Skip to content

Commit 16e5124

Browse files
committed
Make sure we don't spawn workers if all we need are custom ones.
1 parent 0f0b473 commit 16e5124

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

src/ParallelTestRunner.jl

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -689,12 +689,12 @@ function runtests(mod::Module, args::ParsedArgs;
689689
jobs = something(args.jobs, default_njobs())
690690
jobs = clamp(jobs, 1, length(tests))
691691
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.")
692-
workers = addworkers(min(jobs, length(tests)))
693-
nworkers = length(workers)
692+
nworkers = min(jobs, length(tests))
693+
workers = fill(nothing, nworkers)
694694

695695
t0 = time()
696696
results = []
697-
running_tests = Dict{String, Tuple{Int, Float64}}() # test => (worker, start_time)
697+
running_tests = Dict{String, Float64}() # test => start_time
698698
test_lock = ReentrantLock() # to protect crucial access to tests and running_tests
699699

700700
done = false
@@ -755,9 +755,9 @@ function runtests(mod::Module, args::ParsedArgs;
755755
line1 = ""
756756

757757
# line 2: running tests
758-
test_list = sort(collect(running_tests), by = x -> x[2][2])
759-
status_parts = map(test_list) do (test, (wrkr, _))
760-
"$test ($wrkr)"
758+
test_list = sort(collect(keys(running_tests)), by = x -> running_tests[x])
759+
status_parts = map(test_list) do test
760+
"$test"
761761
end
762762
line2 = "Running: " * join(status_parts, ", ")
763763
## truncate
@@ -777,7 +777,7 @@ function runtests(mod::Module, args::ParsedArgs;
777777

778778
est_remaining = 0.0
779779
## currently-running
780-
for (test, (_, start_time)) in running_tests
780+
for (test, start_time) in running_tests
781781
elapsed = time() - start_time
782782
duration = get(historical_durations, test, est_per_test)
783783
est_remaining += max(0.0, duration - elapsed)
@@ -883,21 +883,24 @@ function runtests(mod::Module, args::ParsedArgs;
883883
for p in workers
884884
push!(worker_tasks, @async begin
885885
while !done
886-
# if a worker failed, spawn a new one
887-
if !Malt.isrunning(p)
888-
p = addworker()
889-
end
890-
891886
# get a test to run
892-
test, wrkr, test_t0 = Base.@lock test_lock begin
887+
test, test_t0 = Base.@lock test_lock begin
893888
isempty(tests) && break
894889
test = popfirst!(tests)
895-
wrkr = something(test_worker(test), p)
896890

897891
test_t0 = time()
898-
running_tests[test] = (worker_id(wrkr), test_t0)
892+
running_tests[test] = test_t0
899893

900-
test, wrkr, test_t0
894+
test, test_t0
895+
end
896+
897+
# if a worker failed, spawn a new one
898+
wrkr = test_worker(test)
899+
if wrkr === nothing
900+
wrkr = p
901+
end
902+
if wrkr === nothing || !Malt.isrunning(wrkr)
903+
wrkr = p = addworker()
901904
end
902905

903906
# run the test

0 commit comments

Comments
 (0)