Skip to content

Commit c6edac2

Browse files
authored
Move GC to test_end_expr and only collect when nworkers > 1 (#160)
1 parent 5e610c3 commit c6edac2

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/ReTestItems.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ will be run.
165165
- `worker_init_expr::Expr`: an expression that will be run on each worker process before any tests are run.
166166
Can be used to load packages or set up the environment. Must be a `:block` expression.
167167
- `test_end_expr::Expr`: an expression that will be run after each testitem is run.
168+
By default, the expression is `GC.gc(true)`, when `nworkers > 1`, to help with memory pressure,
169+
otherwise it is a no-op.
168170
Can be used to verify that global state is unchanged after running a test. Must be a `:block` expression.
169171
- `memory_threshold::Real`: Sets the fraction of memory that can be in use before a worker processes are
170172
restarted to free memory. Defaults to $(DEFAULT_MEMORY_THRESHOLD[]). Only supported with `nworkers > 0`.
@@ -240,7 +242,7 @@ function runtests(
240242
report::Bool=parse(Bool, get(ENV, "RETESTITEMS_REPORT", "false")),
241243
logs::Symbol=Symbol(get(ENV, "RETESTITEMS_LOGS", default_log_display_mode(report, nworkers))),
242244
verbose_results::Bool=(logs !== :issues && isinteractive()),
243-
test_end_expr::Expr=Expr(:block),
245+
test_end_expr::Expr=nworkers>1 ? :(GC.gc(true)) : Expr(:block),
244246
validate_paths::Bool=parse(Bool, get(ENV, "RETESTITEMS_VALIDATE_PATHS", "false")),
245247
timeout_profile_wait::Real=parse(Int, get(ENV, "RETESTITEMS_TIMEOUT_PROFILE_WAIT", "0")),
246248
)
@@ -356,10 +358,6 @@ function _runtests_in_current_env(
356358
ts = res.testset
357359
print_errors_and_captured_logs(testitem, run_number; logs)
358360
report_empty_testsets(testitem, ts)
359-
# It takes 2 GCs to do a full mark+sweep
360-
# (the first one is a partial mark, full sweep, the next one is a full mark).
361-
GC.gc(true)
362-
GC.gc(false)
363361
if any_non_pass(ts) && run_number != max_runs
364362
run_number += 1
365363
@info "Retrying $(repr(testitem.name)). Run=$run_number."
@@ -369,6 +367,8 @@ function _runtests_in_current_env(
369367
end
370368
end
371369
elseif !isempty(testitems.testitems)
370+
# Try to free up memory on the coordinator before starting workers
371+
GC.gc(true)
372372
# Use the logger that was set before we eval'd any user code to avoid world age
373373
# issues when logging https://github.com/JuliaLang/julia/issues/33865
374374
original_logger = current_logger()
@@ -546,9 +546,6 @@ function manage_worker(
546546
push!(testitem.stats, testitem_result.stats)
547547
print_errors_and_captured_logs(testitem, run_number; logs)
548548
report_empty_testsets(testitem, ts)
549-
# Run GC to free memory on the worker before next testitem.
550-
@debugv 2 "Running GC on $worker"
551-
remote_fetch(worker, :(GC.gc(true); GC.gc(false)))
552549
if any_non_pass(ts) && run_number != max_runs
553550
run_number += 1
554551
@info "Retrying $(repr(testitem.name)) on $worker. Run=$run_number."

0 commit comments

Comments
 (0)