Skip to content

Commit 313cb4f

Browse files
Store timeout limit as elapsed time when recording error (#94)
* Stored timeout limit as elapsed time when recording error * Bump version * Add comment
1 parent 877bd28 commit 313cb4f

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ReTestItems"
22
uuid = "817f1d60-ba6b-4fd5-9520-3cf149f6a823"
3-
version = "1.12.2"
3+
version = "1.13.0"
44

55
[deps]
66
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

src/ReTestItems.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,15 @@ function record_timeout!(testitem, run_number::Int, timeout_limit::Real)
366366
end
367367
end
368368
msg = "Timed out after $time_str evaluating test item $(repr(testitem.name)) (run=$run_number)"
369-
record_test_error!(testitem, msg)
369+
record_test_error!(testitem, msg, timeout_limit)
370370
end
371371

372372
function record_worker_terminated!(testitem, run_number::Int)
373373
msg = "Worker aborted evaluating test item $(repr(testitem.name)) (run=$run_number)"
374374
record_test_error!(testitem, msg)
375375
end
376376

377-
function record_test_error!(testitem, msg)
377+
function record_test_error!(testitem, msg, elapsed_seconds::Real=0.0)
378378
Test.TESTSET_PRINT_ENABLE[] = false
379379
ts = DefaultTestSet(testitem.name)
380380
err = ErrorException(msg)
@@ -386,6 +386,9 @@ function record_test_error!(testitem, msg)
386386
catch e2
387387
e2 isa TestSetException || rethrow()
388388
end
389+
# Since we're manually constructing a TestSet here to report tests that already ran and
390+
# were killed, we need to manually set how long those tests were running (if known).
391+
ts.time_end = ts.time_start + elapsed_seconds
389392
Test.TESTSET_PRINT_ENABLE[] = true
390393
push!(testitem.testsets, ts)
391394
push!(testitem.stats, PerfStats()) # No data since testitem didn't complete

test/integrationtests.jl

+14
Original file line numberDiff line numberDiff line change
@@ -738,4 +738,18 @@ end
738738
@test_throws expected runtests(file; nworkers=1)
739739
end
740740

741+
@testset "Timeout failures accurately record elapsed time" begin
742+
timeout = 3
743+
results = encased_testset() do
744+
runtests(joinpath(TEST_FILES_DIR, "_timeout_tests.jl"); nworkers=1, testitem_timeout=timeout)
745+
end
746+
# unwrap results down to the testset for the timed-out testitem to check its elapsed time
747+
results = only(results.results) # test
748+
results = only(results.results) # test/testfiles
749+
results = only(results.results) # test/testfiles/_timeout_tests.jl
750+
ts = results.results[1]
751+
@assert ts.description == "Test item takes 60 seconds"
752+
@test ts.time_end - ts.time_start timeout
753+
end
754+
741755
end # integrationtests.jl testset

0 commit comments

Comments
 (0)