Skip to content

Commit

Permalink
feat: pass signal on timeout
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node#43911
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
(cherry picked from commit 2e682f10b6104373fded64b0e364984b85ae2243)
  • Loading branch information
MoLow authored and aduh95 committed Jul 24, 2022
1 parent 10146fa commit 3814bf0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
8 changes: 6 additions & 2 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// https://github.com/nodejs/node/blob/389b7e138e89a339fabe4ad628bf09cd9748f957/lib/internal/test_runner/test.js
// https://github.com/nodejs/node/blob/2e682f10b6104373fded64b0e364984b85ae2243/lib/internal/test_runner/test.js

'use strict'

Expand Down Expand Up @@ -417,7 +417,11 @@ class Test extends AsyncResource {
this.pass()
} catch (err) {
if (err?.code === 'ERR_TEST_FAILURE' && kIsNodeError in err) {
this.fail(err)
if (err.failureType === kTestTimeoutFailure) {
this.cancel(err)
} else {
this.fail(err)
}
} else {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure))
}
Expand Down
3 changes: 2 additions & 1 deletion test/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ async function IsFailureOutput (self, output) {

let waitingForEllipsis = false
for (let i = 0; i < outlines.length; i++) {
let regex
if (patterns[i] === WAIT_FOR_ELLIPSIS) {
waitingForEllipsis = true
} else if (!new RegExp(patterns[i]).test(outlines[i].trimEnd())) {
} else if (!(regex = new RegExp(patterns[i])).test(outlines[i]) && !regex.test(outlines[i].trimEnd())) {
if (waitingForEllipsis) {
patterns.splice(i, 0, WAIT_FOR_ELLIPSIS)
continue
Expand Down
8 changes: 4 additions & 4 deletions test/message/test_runner_output.out
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ not ok 13 - async assertion fail
failureType: 'testCodeFailure'
error: |-
Expected values to be strictly equal:

true !== false

code: 'ERR_ASSERTION'
stack: |-
*
Expand Down Expand Up @@ -607,8 +607,8 @@ not ok 61 - invalid subtest fail
# 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.
# tests 61
# pass 26
# fail 20
# cancelled 0
# fail 18
# cancelled 2
# skipped 10
# todo 5
# duration_ms *
35 changes: 35 additions & 0 deletions test/parallel/test-runner-misc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// https://github.com/nodejs/node/blob/2e682f10b6104373fded64b0e364984b85ae2243/test/parallel/test-runner-misc.js

'use strict'
const common = require('../common')
const assert = require('assert')
const { spawnSync } = require('child_process')
const { setTimeout } = require('timers/promises')

if (process.argv[2] === 'child') {
const test = require('node:test')

if (process.argv[3] === 'abortSignal') {
assert.throws(() => test({ signal: {} }), {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
})

let testSignal
test({ timeout: 10 }, common.mustCall(async ({ signal }) => {
assert.strictEqual(signal.aborted, false)
testSignal = signal
await setTimeout(50)
})).finally(common.mustCall(() => {
test(() => assert.strictEqual(testSignal.aborted, true))
}))
} else assert.fail('unreachable')
} else {
const child = spawnSync(process.execPath, [__filename, 'child', 'abortSignal'])
const stdout = child.stdout.toString()
assert.match(stdout, /^# pass 1$/m)
assert.match(stdout, /^# fail 0$/m)
assert.match(stdout, /^# cancelled 1$/m)
assert.strictEqual(child.status, 1)
assert.strictEqual(child.signal, null)
}

0 comments on commit 3814bf0

Please sign in to comment.