Skip to content

Commit 3814bf0

Browse files
MoLowaduh95
authored andcommitted
feat: pass signal on timeout
PR-URL: nodejs/node#43911 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> (cherry picked from commit 2e682f10b6104373fded64b0e364984b85ae2243)
1 parent 10146fa commit 3814bf0

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

lib/internal/test_runner/test.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// https://github.com/nodejs/node/blob/389b7e138e89a339fabe4ad628bf09cd9748f957/lib/internal/test_runner/test.js
1+
// https://github.com/nodejs/node/blob/2e682f10b6104373fded64b0e364984b85ae2243/lib/internal/test_runner/test.js
22

33
'use strict'
44

@@ -417,7 +417,11 @@ class Test extends AsyncResource {
417417
this.pass()
418418
} catch (err) {
419419
if (err?.code === 'ERR_TEST_FAILURE' && kIsNodeError in err) {
420-
this.fail(err)
420+
if (err.failureType === kTestTimeoutFailure) {
421+
this.cancel(err)
422+
} else {
423+
this.fail(err)
424+
}
421425
} else {
422426
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure))
423427
}

test/message.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ async function IsFailureOutput (self, output) {
6060

6161
let waitingForEllipsis = false
6262
for (let i = 0; i < outlines.length; i++) {
63+
let regex
6364
if (patterns[i] === WAIT_FOR_ELLIPSIS) {
6465
waitingForEllipsis = true
65-
} else if (!new RegExp(patterns[i]).test(outlines[i].trimEnd())) {
66+
} else if (!(regex = new RegExp(patterns[i])).test(outlines[i]) && !regex.test(outlines[i].trimEnd())) {
6667
if (waitingForEllipsis) {
6768
patterns.splice(i, 0, WAIT_FOR_ELLIPSIS)
6869
continue

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

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

0 commit comments

Comments
 (0)