Skip to content

Commit f25832e

Browse files
authored
[RAI-28133] Output an error when worker_init_expr is set but test workers are zero (#162)
Currently, if test workers are zero, `worker_init_expr` won't run even if it's defined. This PR returns an error in this case. A `@testset` is added in `test/integrationtests.jl`. * error when worker_init_expr is set with zero workers
1 parent c6edac2 commit f25832e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/ReTestItems.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ function _runtests_in_current_env(
343343
(nworkers == 0 ? "" : " with $nworkers worker processes and $nworker_threads threads per worker.")
344344
try
345345
if nworkers == 0
346+
length(worker_init_expr.args) > 0 && error("worker_init_expr is set, but will not run because number of workers is 0.")
346347
# This is where we disable printing for the serial executor case.
347348
Test.TESTSET_PRINT_ENABLE[] = false
348349
ctx = TestContext(proj_name, ntestitems)

test/integrationtests.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,17 @@ end
224224
end
225225
end
226226

227+
@testset "runtests a dir with 0 nworkers but worker_init_expr set" verbose=true begin
228+
# Doesn't actually matter what it's set to, just that it's set.
229+
worker_init_expr =:(1+1)
230+
results = encased_testset() do
231+
runtests(joinpath(TEST_PKG_DIR, "NoDeps.jl"); worker_init_expr)
232+
end
233+
234+
@test n_passed(results) == 0
235+
@test length(errors(results)) == 1
236+
end
237+
227238
nworkers = 2
228239
@testset "runtests with nworkers = $nworkers" verbose=true begin
229240
@testset "Pkg.test() $pkg" for pkg in TEST_PKGS

0 commit comments

Comments
 (0)