Skip to content

Commit c497fee

Browse files
committed
Better isolation of tests in juliatests
1 parent 70580fd commit c497fee

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

test/juliatests.jl

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ end
4343

4444
tests, _, exit_on_error, seed = choosetests(ARGS)
4545

46+
function spin_up_worker()
47+
p = addprocs(1)[1]
48+
remotecall_wait(include, p, "utils.jl")
49+
remotecall_wait(configure_test, p)
50+
return p
51+
end
52+
4653
function spin_up_workers(n)
4754
procs = addprocs(n)
4855
@sync begin
@@ -71,27 +78,35 @@ move_to_node1("Distributed")
7178
@testset "Julia tests" begin
7279
nworkers = min(Sys.CPU_THREADS, length(tests))
7380
println("Using $nworkers workers")
74-
procs = spin_up_workers(nworkers)
7581
results = Dict{String,Any}()
7682
tests0 = copy(tests)
77-
all_tasks = Task[]
83+
all_tasks = Union{Task,Nothing}[]
7884
try
7985
@sync begin
80-
for p in procs
86+
for i = 1:nworkers
8187
@async begin
8288
push!(all_tasks, current_task())
8389
while length(tests) > 0
90+
nleft = length(tests)
8491
test = popfirst!(tests)
92+
println(nleft, " remaining, starting ", test, " on task ", i)
8593
local resp
8694
fullpath = test_path(test) * ".jl"
8795
try
88-
resp = remotecall_fetch(run_test_by_eval, p, test, fullpath, nstmts)
96+
resp = disable_sigint() do
97+
p = spin_up_worker()
98+
result = remotecall_fetch(run_test_by_eval, p, test, fullpath, nstmts)
99+
rmprocs(p; waitfor=5)
100+
result
101+
end
89102
catch e
90-
isa(e, InterruptException) && return
103+
if isa(e, InterruptException)
104+
println("interrupting ", test)
105+
break # rethrow(e)
106+
end
91107
resp = e
92108
if isa(e, ProcessExitedException)
93109
println("exited on ", test)
94-
p = spin_up_workers(1)[1]
95110
end
96111
end
97112
results[test] = resp
@@ -100,14 +115,24 @@ move_to_node1("Distributed")
100115
empty!(tests)
101116
end
102117
end
118+
println("Task ", i, " complete")
119+
all_tasks[i] = nothing
103120
end
104121
end
105122
end
106123
catch err
107-
isa(err, InterruptException) || rethrow(err)
124+
isa(err, InterruptException) || rethrow(err)
108125
# If the test suite was merely interrupted, still print the
109126
# summary, which can be useful to diagnose what's going on
110-
foreach(task->try; schedule(task, InterruptException(); error=true); catch; end, all_tasks)
127+
foreach(all_tasks) do task
128+
try
129+
if isa(task, Task)
130+
println("trying to interrupt ", task)
131+
schedule(task, InterruptException(); error=true)
132+
end
133+
catch
134+
end
135+
end
111136
foreach(wait, all_tasks)
112137
end
113138

@@ -120,8 +145,7 @@ move_to_node1("Distributed")
120145
println(io, "| Test file | Passes | Fails | Errors | Broken | Aborted blocks |")
121146
println(io, "| --------- | ------:| -----:| ------:| ------:| --------------:|")
122147
for test in tests0
123-
haskey(results, test) || (@warn "missing $test"; continue)
124-
result = results[test]
148+
result = get(results, test, "")
125149
if isa(result, Tuple{Test.AbstractTestSet, Vector})
126150
ts, aborts = result
127151
passes, fails, errors, broken, c_passes, c_fails, c_errors, c_broken = Test.get_test_counts(ts)

test/utils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ function run_test_by_eval(test, fullpath, nstmts)
174174
nstmtsleft = $nstmts
175175
frame = JuliaInterpreter.prepare_thunk(modex)
176176
while true
177+
yield() # allow communication between processes
177178
ret, nstmtsleft = evaluate_limited!(stack, frame, nstmtsleft)
178179
isa(ret, Some{Any}) && break
179180
if isa(ret, Aborted)

0 commit comments

Comments
 (0)