Skip to content

Commit 3fbada9

Browse files
Log a message when each worker has completed tests
1 parent 5a92d85 commit 3fbada9

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/ReTestItems.jl

Lines changed: 6 additions & 3 deletions
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
@@ -580,16 +580,18 @@ function record_test_error!(testitem, msg, elapsed_seconds::Real=0.0)
580580
return testitem
581581
end
582582

583+
# The provided `worker_num` is only for logging purposes, and not persisted as part of the worker.
583584
function manage_worker(
584-
worker::Worker, proj_name::AbstractString, testitems::TestItems, testitem::Union{TestItem,Nothing}, cfg::_Config,
585+
worker::Worker, proj_name::AbstractString, testitems::TestItems, testitem::Union{TestItem,Nothing}, cfg::_Config;
586+
worker_num::Int
585587
)
586588
ntestitems = length(testitems.testitems)
587589
run_number = 1
588590
memory_threshold_percent = 100 * cfg.memory_threshold
589591
while testitem !== nothing
590592
ch = Channel{TestItemResult}(1)
591593
if memory_percent() > memory_threshold_percent
592-
@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."
594+
@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."
593595
terminate!(worker)
594596
wait(worker)
595597
worker = robust_start_worker(proj_name, cfg.nworker_threads, cfg.worker_init_expr, ntestitems)
@@ -697,6 +699,7 @@ function manage_worker(
697699
continue
698700
end
699701
end
702+
@info "All tests on worker $worker_num completed. Closing $worker."
700703
close(worker)
701704
return nothing
702705
end

src/workers.jl

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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)