Skip to content

Commit

Permalink
Log a message when each worker has completed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrobinson251 committed Oct 21, 2024
1 parent d094db8 commit 0420a84
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/ReTestItems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ function _runtests_in_current_env(
ti = starting[i]
@spawn begin
with_logger(original_logger) do
manage_worker($w, $proj_name, $testitems, $ti, $cfg)
manage_worker($w, $proj_name, $testitems, $ti, $cfg; worker_num=$i)
end
end
end
Expand Down Expand Up @@ -575,16 +575,18 @@ function record_test_error!(testitem, msg, elapsed_seconds::Real=0.0)
return testitem
end

# The provided `worker_num` is only for logging purposes, and not persisted as part of the worker.
function manage_worker(
worker::Worker, proj_name::AbstractString, testitems::TestItems, testitem::Union{TestItem,Nothing}, cfg::_Config,
worker::Worker, proj_name::AbstractString, testitems::TestItems, testitem::Union{TestItem,Nothing}, cfg::_Config;
worker_num::Int
)
ntestitems = length(testitems.testitems)
run_number = 1
memory_threshold_percent = 100 * cfg.memory_threshold
while testitem !== nothing
ch = Channel{TestItemResult}(1)
if memory_percent() > memory_threshold_percent
@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."
@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."
terminate!(worker)
wait(worker)
worker = robust_start_worker(proj_name, cfg.nworker_threads, cfg.worker_init_expr, ntestitems)
Expand Down Expand Up @@ -692,6 +694,7 @@ function manage_worker(
continue
end
end
@info "All tests on worker $worker_num completed. Closing $worker."
close(worker)
return nothing
end
Expand Down
2 changes: 2 additions & 0 deletions src/workers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,15 @@ end
# gracefully terminate a worker by sending a shutdown message
# and waiting for the other tasks to perform worker shutdown
function Base.close(w::Worker)
@debugv 2 "closing worker $(w.pid)"
if !w.terminated && isopen(w.socket)
req = Request(Symbol(), :(), rand(UInt64), true)
@lock w.lock begin
serialize(w.socket, req)
flush(w.socket)
end
end
@debugv 2 "waiting for worker $(w.pid) to terminate"
wait(w)
return
end
Expand Down
2 changes: 1 addition & 1 deletion test/integrationtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ end
# monkey-patch the internal `memory_percent` function to return a fixed value, so we
# can control if we hit the `memory_threshold`.
@eval ReTestItems.memory_percent() = 83.1
expected_warning = "Warning: Memory usage (83.1%) is higher than threshold (7.0%). Restarting worker process to try to free memory."
expected_warning = "Warning: Memory usage (83.1%) is higher than threshold (7.0%). Restarting process for worker 1 to try to free memory."

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

0 comments on commit 0420a84

Please sign in to comment.