From e52d080ed43328813eb40d5c9a4cb9ddd78f3c2f Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Tue, 27 Oct 2026 16:20:18 +0100 Subject: [PATCH 1/3] Avoid boxed captured variables in `runtests` `historical_durations` and `historical_failures` were assigned on two paths and captured, and the local `create_testset` has keyword arguments, so both were stored in a `Core.Box` and lost their type. Load the history once, and make `create_testset` a top-level function since it captures nothing. --- src/ParallelTestRunner.jl | 59 ++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/ParallelTestRunner.jl b/src/ParallelTestRunner.jl index 9611e74..22ac83c 100644 --- a/src/ParallelTestRunner.jl +++ b/src/ParallelTestRunner.jl @@ -248,9 +248,10 @@ function runtests(mod::Module, args::ParsedArgs; # set-up # + historical_durations, historical_failures = load_test_history(mod, history_key) + # list tests, if requested if args.list !== nothing - historical_durations, historical_failures = load_test_history(mod, history_key) sorted_tests = sort(collect(keys(testsuite))) name_align = isempty(sorted_tests) ? 0 : maximum(textwidth, sorted_tests) duration_strs = Dict( @@ -282,7 +283,6 @@ function runtests(mod::Module, args::ParsedArgs; # determine test order tests = collect(keys(testsuite)) Random.shuffle!(tests) - historical_durations, historical_failures = load_test_history(mod, history_key) get_historical_duration(test) = TestHistoryEntry(get(historical_durations, test, Inf), test in historical_failures) sort!(tests, by = x -> get_historical_duration(x), rev = true) @@ -320,6 +320,34 @@ const SLOW_INIT_FACTOR = 2 # with a short cold worker init const SLOW_INIT_MIN_TIME = 10.0 +# create a testset to record test results in, with the given timings if supported +function create_testset(name; start=nothing, stop=nothing, kwargs...) + if start === nothing + testset = Test.DefaultTestSet(name; kwargs...) + elseif VERSION >= v"1.13.0-DEV.1297" + testset = Test.DefaultTestSet(name; time_start=start, kwargs...) + elseif VERSION < v"1.13.0-DEV.1037" + testset = Test.DefaultTestSet(name; kwargs...) + testset.time_start = start + else + # no way to set time_start retroactively + testset = Test.DefaultTestSet(name; kwargs...) + end + + if stop !== nothing + if VERSION < v"1.13.0-DEV.1037" + testset.time_end = stop + elseif VERSION >= v"1.13.0-DEV.1297" + @atomic testset.time_end = stop + else + # if we can't set the start time, also don't set a stop one + # to avoid negative timings + end + end + + return testset +end + # Helper function, to be used for testing, with `tests` already sorted. function _runtests(mod::Module, args::ParsedArgs; testsuite::Dict{String,Expr} = find_tests(pwd()), @@ -904,33 +932,6 @@ function _runtests(mod::Module, args::ParsedArgs; end end - # process test results and convert into a testset - function create_testset(name; start=nothing, stop=nothing, kwargs...) - if start === nothing - testset = Test.DefaultTestSet(name; kwargs...) - elseif VERSION >= v"1.13.0-DEV.1297" - testset = Test.DefaultTestSet(name; time_start=start, kwargs...) - elseif VERSION < v"1.13.0-DEV.1037" - testset = Test.DefaultTestSet(name; kwargs...) - testset.time_start = start - else - # no way to set time_start retroactively - testset = Test.DefaultTestSet(name; kwargs...) - end - - if stop !== nothing - if VERSION < v"1.13.0-DEV.1037" - testset.time_end = stop - elseif VERSION >= v"1.13.0-DEV.1297" - @atomic testset.time_end = stop - else - # if we can't set the start time, also don't set a stop one - # to avoid negative timings - end - end - - return testset - end t1 = time() o_ts = create_testset("Overall"; start=t0, stop=t1, verbose=!isnothing(args.verbose)) function collect_results() From 105213fe9e178286b95c61d4444d6071d1e54c35 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Tue, 27 Oct 2026 16:20:18 +0100 Subject: [PATCH 2/3] Test that no captured variables are boxed Use `Test.detect_closure_boxes`, available on Julia 1.14 and later. --- test/runtests.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 7f04ca4..f2b79be 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,6 +11,13 @@ filter!(testsuite) do (name, _) name != "utils" && !startswith(name, "sample_tests/") end +# captured variables that get boxed (`Core.Box`) lose their type +if isdefined(Test, :detect_closure_boxes) + testsuite["closure boxes"] = quote + @test Test.detect_closure_boxes(ParallelTestRunner) == [] + end +end + init_code = quote using ParallelTestRunner using Test From 89fb6156eae678bc061dd84e3f03eec39e34a6ef Mon Sep 17 00:00:00 2001 From: Christian Guinard <28689358+christiangnrd@users.noreply.github.com> Date: Sat, 31 Oct 2026 15:02:55 -0300 Subject: [PATCH 3/3] Move `create_testset` to compatutils.jl --- src/ParallelTestRunner.jl | 30 +----------------------------- src/compatutils.jl | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/ParallelTestRunner.jl b/src/ParallelTestRunner.jl index 22ac83c..87cb360 100644 --- a/src/ParallelTestRunner.jl +++ b/src/ParallelTestRunner.jl @@ -17,7 +17,7 @@ if VERSION >= v"1.13.0-DEV.1044" using Base.ScopedValues end -# anyonpass, Lockable, with_testset, available_memory +# anyonpass, Lockable, with_testset, available_memory, create_testset include("compatutils.jl") # PTRWorker, worker_id, test_exe, addworkers, addworker @@ -320,34 +320,6 @@ const SLOW_INIT_FACTOR = 2 # with a short cold worker init const SLOW_INIT_MIN_TIME = 10.0 -# create a testset to record test results in, with the given timings if supported -function create_testset(name; start=nothing, stop=nothing, kwargs...) - if start === nothing - testset = Test.DefaultTestSet(name; kwargs...) - elseif VERSION >= v"1.13.0-DEV.1297" - testset = Test.DefaultTestSet(name; time_start=start, kwargs...) - elseif VERSION < v"1.13.0-DEV.1037" - testset = Test.DefaultTestSet(name; kwargs...) - testset.time_start = start - else - # no way to set time_start retroactively - testset = Test.DefaultTestSet(name; kwargs...) - end - - if stop !== nothing - if VERSION < v"1.13.0-DEV.1037" - testset.time_end = stop - elseif VERSION >= v"1.13.0-DEV.1297" - @atomic testset.time_end = stop - else - # if we can't set the start time, also don't set a stop one - # to avoid negative timings - end - end - - return testset -end - # Helper function, to be used for testing, with `tests` already sorted. function _runtests(mod::Module, args::ParsedArgs; testsuite::Dict{String,Expr} = find_tests(pwd()), diff --git a/src/compatutils.jl b/src/compatutils.jl index 88b0af0..c5ce09d 100644 --- a/src/compatutils.jl +++ b/src/compatutils.jl @@ -93,3 +93,32 @@ end else available_memory() = Sys.free_memory() end + + +# create a testset to record test results in, with the given timings if supported +function create_testset(name; start=nothing, stop=nothing, kwargs...) + if start === nothing + testset = Test.DefaultTestSet(name; kwargs...) + elseif VERSION >= v"1.13.0-DEV.1297" + testset = Test.DefaultTestSet(name; time_start=start, kwargs...) + elseif VERSION < v"1.13.0-DEV.1037" + testset = Test.DefaultTestSet(name; kwargs...) + testset.time_start = start + else + # no way to set time_start retroactively + testset = Test.DefaultTestSet(name; kwargs...) + end + + if stop !== nothing + if VERSION < v"1.13.0-DEV.1037" + testset.time_end = stop + elseif VERSION >= v"1.13.0-DEV.1297" + @atomic testset.time_end = stop + else + # if we can't set the start time, also don't set a stop one + # to avoid negative timings + end + end + + return testset +end