Skip to content

Commit c32464f

Browse files
Log a message when each worker has completed tests
1 parent e9b7730 commit c32464f

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/ReTestItems.jl

+6-3
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ function _runtests_in_current_env(
443443
ti = starting[i]
444444
@spawn begin
445445
with_logger(original_logger) do
446-
manage_worker($w, $proj_name, $testitems, $ti, $cfg)
446+
manage_worker($w, $proj_name, $testitems, $ti, $cfg; worker_num=$i)
447447
end
448448
end
449449
end
@@ -575,16 +575,18 @@ function record_test_error!(testitem, msg, elapsed_seconds::Real=0.0)
575575
return testitem
576576
end
577577

578+
# The provided `worker_num` is only for logging purposes, and not persisted as part of the worker.
578579
function manage_worker(
579-
worker::Worker, proj_name::AbstractString, testitems::TestItems, testitem::Union{TestItem,Nothing}, cfg::_Config,
580+
worker::Worker, proj_name::AbstractString, testitems::TestItems, testitem::Union{TestItem,Nothing}, cfg::_Config;
581+
worker_num::Int
580582
)
581583
ntestitems = length(testitems.testitems)
582584
run_number = 1
583585
memory_threshold_percent = 100 * cfg.memory_threshold
584586
while testitem !== nothing
585587
ch = Channel{TestItemResult}(1)
586588
if memory_percent() > memory_threshold_percent
587-
@warn "Memory usage ($(Base.Ryu.writefixed(memory_percent(), 1))%) is higher than threshold ($(Base.Ryu.writefixed(memory_threshold_percent, 1))%). Restarting worker process to try to free memory."
589+
@warn "Memory usage ($(Base.Ryu.writefixed(memory_percent(), 1))%) is higher than threshold ($(Base.Ryu.writefixed(memory_threshold_percent, 1))%). Restarting process for worker $worker_num to try to free memory."
588590
terminate!(worker)
589591
wait(worker)
590592
worker = robust_start_worker(proj_name, cfg.nworker_threads, cfg.worker_init_expr, ntestitems)
@@ -692,6 +694,7 @@ function manage_worker(
692694
continue
693695
end
694696
end
697+
@info "All tests on worker $worker_num completed. Closing $worker."
695698
close(worker)
696699
return nothing
697700
end

src/workers.jl

+2
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,15 @@ end
128128
# gracefully terminate a worker by sending a shutdown message
129129
# and waiting for the other tasks to perform worker shutdown
130130
function Base.close(w::Worker)
131+
@debugv 2 "closing worker $(w.pid)"
131132
if !w.terminated && isopen(w.socket)
132133
req = Request(Symbol(), :(), rand(UInt64), true)
133134
@lock w.lock begin
134135
serialize(w.socket, req)
135136
flush(w.socket)
136137
end
137138
end
139+
@debugv 2 "waiting for worker $(w.pid) to terminate"
138140
wait(w)
139141
return
140142
end

test/integrationtests.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ end
12121212
# monkey-patch the internal `memory_percent` function to return a fixed value, so we
12131213
# can control if we hit the `memory_threshold`.
12141214
@eval ReTestItems.memory_percent() = 83.1
1215-
expected_warning = "Warning: Memory usage (83.1%) is higher than threshold (7.0%). Restarting worker process to try to free memory."
1215+
expected_warning = "Warning: Memory usage (83.1%) is higher than threshold (7.0%). Restarting process for worker 1 to try to free memory."
12161216

12171217
# Pass `memory_threshold` keyword, and hit the memory threshold.
12181218
c1 = IOCapture.capture() do

0 commit comments

Comments
 (0)