Repository navigation
Make timeout work for synchronous tests - #3495
ericcornelissen wants to merge 3 commits into
Conversation
|
Is the change to reported teardown duration intentional in @ericcornelissen's synchronous-timeout fix? import test from 'ava';
import {setTimeout as delay} from 'node:timers/promises';
test('slow cleanup', t => {
t.teardown(() => delay(300));
t.pass();
});In the recorded Linux / Node v24.19.0 comparison, across three runs per ref, the real Could the pre-teardown timestamp be kept for checking the timeout while measuring reported duration after teardown? The existing timeout scope can stay the same: a quick body with The added synchronous fixture passes on the pre-PR baseline and correctly fails with a timeout on the head. Focused runs passed on both refs: |
Fail a (synchronous) test when its runtime exceeds the configured timeout value. This prevents tests with long runtimes but no asynchronicity from succeeding. The added test fixture demonstrates this. Before this change such a test would pass but with this change it will fail because it exceeds the configured timeout.
|
Thanks for the review @hafizahmedzia, that's probably not how it should work so I'll adjust it. I will also try to add a test (for both) to catch such regressions going forward. |
d9a4614 to
a4251bc
Compare
Extend the synchronous timeout behavior to, like the asynchronous timeout behavior, reset the timer, through `refreshTimeout`, on (e.g.) assertions.
Don't reuse the `now` value to determine if the test timeout/deadline was met to compute the (overall) test duration. This is in line with async tests, which only fail if the test itself, excluding teardown, exceeded the configured timeout (verified manually). To catch regression like this in the future I (tried) added a tests that assert the output of AVA includes the test duration for long running tests AND long running teardowns in its output.
a4251bc to
06d5772
Compare
Closes #3454
This changes the
Testclass to fail when its runtime exceeds the configured timeout value. This prevents tests with long runtimes but no asynchronicity from succeeding, as illustrated by the added test fixture.Like with asynchronous timeouts, the synchronous timeout is reset in the
refreshTimeoutmethod. This makes the behavior consistent and was forced by the pre-existing test suite.If you want I can spend a bit more time trying to reduce the duplication. Also, I'm unsure about the
returnon line 467 as the test suite passes regardless of whether or not it's there.