Skip to content

Commit a167daa

Browse files
MoLowtargos
authored andcommitted
test_runner: pass signal on timeout
PR-URL: #43911 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent b1db850 commit a167daa

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

lib/internal/test_runner/test.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,11 @@ class Test extends AsyncResource {
414414
this.pass();
415415
} catch (err) {
416416
if (err?.code === 'ERR_TEST_FAILURE' && kIsNodeError in err) {
417-
this.fail(err);
417+
if (err.failureType === kTestTimeoutFailure) {
418+
this.cancel(err);
419+
} else {
420+
this.fail(err);
421+
}
418422
} else {
419423
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
420424
}

test/message/test_runner_output.out

+4-4
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ not ok 13 - async assertion fail
129129
failureType: 'testCodeFailure'
130130
error: |-
131131
Expected values to be strictly equal:
132-
132+
133133
true !== false
134-
134+
135135
code: 'ERR_ASSERTION'
136136
stack: |-
137137
*
@@ -607,8 +607,8 @@ not ok 61 - invalid subtest fail
607607
# Warning: Test "callback async throw after done" generated asynchronous activity after the test ended. This activity created the error "Error: thrown from callback async throw after done" and would have caused the test to fail, but instead triggered an uncaughtException event.
608608
# tests 61
609609
# pass 26
610-
# fail 20
611-
# cancelled 0
610+
# fail 18
611+
# cancelled 2
612612
# skipped 10
613613
# todo 5
614614
# duration_ms *

test/parallel/test-runner-misc.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const { spawnSync } = require('child_process');
5+
const { setTimeout } = require('timers/promises');
6+
7+
if (process.argv[2] === 'child') {
8+
const test = require('node:test');
9+
10+
if (process.argv[3] === 'abortSignal') {
11+
assert.throws(() => test({ signal: {} }), {
12+
code: 'ERR_INVALID_ARG_TYPE',
13+
name: 'TypeError'
14+
});
15+
16+
let testSignal;
17+
test({ timeout: 10 }, common.mustCall(async ({ signal }) => {
18+
assert.strictEqual(signal.aborted, false);
19+
testSignal = signal;
20+
await setTimeout(50);
21+
})).finally(common.mustCall(() => {
22+
test(() => assert.strictEqual(testSignal.aborted, true));
23+
}));
24+
} else assert.fail('unreachable');
25+
} else {
26+
const child = spawnSync(process.execPath, [__filename, 'child', 'abortSignal']);
27+
const stdout = child.stdout.toString();
28+
assert.match(stdout, /^# pass 1$/m);
29+
assert.match(stdout, /^# fail 0$/m);
30+
assert.match(stdout, /^# cancelled 1$/m);
31+
assert.strictEqual(child.status, 1);
32+
assert.strictEqual(child.signal, null);
33+
}

0 commit comments

Comments
 (0)