Skip to content

Commit 11f4f78

Browse files
committed
More simplifications: rely on Malt.isrunning.
1 parent 99fe417 commit 11f4f78

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

src/ParallelTestRunner.jl

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -378,36 +378,25 @@ end
378378
# Map PIDs to logical worker IDs
379379
# Malt doesn't have a global worker ID, and PID make printing ugly
380380
const WORKER_IDS = Dict{Int32, Int32}()
381-
382381
worker_id(wrkr) = WORKER_IDS[wrkr.proc_pid]
383382

384383
"""
385384
addworkers(X; kwargs...)
386385
387386
Add `X` worker processes.
388387
"""
389-
function addworkers(X; env=Vector{Pair{String, String}}())
388+
addworkers(X; kwargs...) = [addworker(; kwargs...) for _ in 1:X]
389+
function addworker(; env=Vector{Pair{String, String}}())
390390
exe = test_exe()
391391
exeflags = exe[2:end]
392392

393393
push!(env, "JULIA_NUM_THREADS" => "1")
394394
# Malt already sets OPENBLAS_NUM_THREADS to 1
395395
push!(env, "OPENBLAS_NUM_THREADS" => "1")
396396

397-
workers = Malt.Worker[]
398-
for _ in 1:X
399-
wrkr = Malt.Worker(;exeflags, env)
400-
WORKER_IDS[wrkr.proc_pid] = length(WORKER_IDS) + 1
401-
push!(workers, wrkr)
402-
end
403-
return workers
404-
end
405-
addworker(; kwargs...) = addworkers(1; kwargs...)[1]
406-
407-
function recycle_worker(w::Malt.Worker)
408-
Malt.stop(w; exit_timeout = 15.0, term_timeout = 15.0)
409-
410-
return nothing
397+
wrkr = Malt.Worker(;exeflags, env)
398+
WORKER_IDS[wrkr.proc_pid] = length(WORKER_IDS) + 1
399+
return wrkr
411400
end
412401

413402
"""
@@ -780,7 +769,7 @@ function runtests(mod::Module, ARGS; test_filter = Returns(true), RecordType = T
780769
push!(worker_tasks, @async begin
781770
while !done
782771
# if a worker failed, spawn a new one
783-
if p === nothing
772+
if !Malt.isrunning(p)
784773
p = addworker()
785774
end
786775

@@ -822,7 +811,7 @@ function runtests(mod::Module, ARGS; test_filter = Returns(true), RecordType = T
822811
if memory_usage(result) > max_worker_rss
823812
# the worker has reached the max-rss limit, recycle it
824813
# so future tests start with a smaller working set
825-
p = recycle_worker(p)
814+
Malt.stop(wrkr)
826815
end
827816
else
828817
@assert result isa Exception
@@ -832,12 +821,12 @@ function runtests(mod::Module, ARGS; test_filter = Returns(true), RecordType = T
832821
end
833822

834823
# the worker encountered some serious failure, recycle it
835-
p = recycle_worker(p)
824+
Malt.stop(wrkr)
836825
end
837826

838827
# get rid of the custom worker
839828
if wrkr != p
840-
recycle_worker(wrkr)
829+
Malt.stop(wrkr)
841830
end
842831

843832
delete!(running_tests, test)

0 commit comments

Comments
 (0)