Repository navigation
Make timeout work for synchronous tests - #3495
ericcornelissen wants to merge 2 commits into
Conversation
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.
Extend the synchronous timeout behavior to, like the asynchronous timeout behavior, reset the timer, through `refreshTimeout`, on (e.g.) assertions.
|
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: |
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.