Skip to content

Commit f243cab

Browse files
Do not count writes to stdout/stderr as non-idling activity for timeouts
Fixes #3373. The idle guard will now force a test worker to exit even if it's continuously writing to stdout/stderr. Co-authored-by: Mark Wubben <[email protected]>
1 parent 4abb780 commit f243cab

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

lib/api.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,8 @@ export default class Api extends Emittery {
218218
}
219219

220220
runStatus.on('stateChange', record => {
221-
if (record.testFile && !timedOutWorkerFiles.has(record.testFile)) {
222-
// Debounce the timer whenever there is activity from workers that
223-
// haven't already timed out.
221+
if (record.testFile && !timedOutWorkerFiles.has(record.testFile) && record.type !== 'worker-stderr' && record.type !== 'worker-stdout') {
222+
// Debounce the timer whenever there is test-related activity from workers that haven't already timed out.
224223
timeoutTrigger.debounce();
225224
}
226225

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {setTimeout as delay} from 'node:timers/promises';
2+
import test from 'ava';
3+
4+
test('timeout with console output', async t => {
5+
t.timeout(1000, 'timeout despite console output');
6+
for (let i = 0; await delay(100, true); i++) {
7+
if (i % 2 === 0) {
8+
console.log('stdout');
9+
} else {
10+
console.error('stderr');
11+
}
12+
}
13+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "module",
3+
"ava": {
4+
"files": [
5+
"*.js"
6+
],
7+
"timeout": "500ms"
8+
}
9+
}

test/idle-timeouts/test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import test from '@ava/test';
2+
3+
import {fixture} from '../helpers/exec.js';
4+
5+
test('idle timeouts are not blocked by console output', async t => {
6+
const result = await t.throwsAsync(fixture(['console-output.js']));
7+
const error = result.stats.getError(result.stats.failed[0]);
8+
t.is(error.message, 'timeout despite console output');
9+
});

0 commit comments

Comments
 (0)