Skip to content

Commit ded18ad

Browse files
committed
Support init_worker_code with custom workers
1 parent 60f782f commit ded18ad

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/ParallelTestRunner.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ Several keyword arguments are also supported:
686686
- `init_code`: Code use to initialize each test's sandbox module (e.g., import auxiliary
687687
packages, define constants, etc).
688688
- `init_worker_code`: Code use to initialize each worker. This is run only once per worker instead of once per test.
689-
- `test_worker`: Optional function that takes a test name and returns a specific worker.
689+
- `test_worker`: Optional function that takes a test name and `init_worker_code` if `init_worker_code` is defined and returns a specific worker.
690690
When returning `nothing`, the test will be assigned to any available default worker.
691691
- `stdout` and `stderr`: I/O streams to write to (default: `Base.stdout` and `Base.stderr`)
692692
@@ -996,11 +996,16 @@ function runtests(mod::Module, args::ParsedArgs;
996996
test, test_t0
997997
end
998998

999-
# if a worker failed, spawn a new one
1000-
wrkr = test_worker(test)
1001-
if wrkr === nothing
999+
# pass in init_worker_code to custom worker function if defined
1000+
wrkr = if init_worker_code == :()
1001+
test_worker(test)
1002+
else
1003+
test_worker(test, init_worker_code)
1004+
end
1005+
if wrkr === nothing
10021006
wrkr = p
10031007
end
1008+
# if a worker failed, spawn a new one
10041009
if wrkr === nothing || !Malt.isrunning(wrkr)
10051010
wrkr = p = addworker(; init_worker_code, io_ctx.color)
10061011
end

0 commit comments

Comments
 (0)