From 235ea83a1f783c387fe627c03a3277e503002d1e Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Wed, 20 Jul 2022 15:52:18 +0300 Subject: [PATCH 1/3] test_runner: pass signal on timeout --- lib/internal/test_runner/test.js | 6 +++++- test/message/test_runner_output.out | 8 +++---- test/parallel/test-runner-misc.js | 33 +++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 test/parallel/test-runner-misc.js diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 0755c42750ac87..d2be83364a0f6d 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -414,7 +414,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)); } diff --git a/test/message/test_runner_output.out b/test/message/test_runner_output.out index 22d97940a36f9c..4e987f8e9f4b94 100644 --- a/test/message/test_runner_output.out +++ b/test/message/test_runner_output.out @@ -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: |- * @@ -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 * diff --git a/test/parallel/test-runner-misc.js b/test/parallel/test-runner-misc.js new file mode 100644 index 00000000000000..2834b9833bdc87 --- /dev/null +++ b/test/parallel/test-runner-misc.js @@ -0,0 +1,33 @@ +'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); + })).then(() => { + 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/); + assert.match(stdout, /# fail 0/); + assert.match(stdout, /# cancelled 1/); + assert.strictEqual(child.status, 1); + assert.strictEqual(child.signal, null); +} From 1d2898ac57e86088804cf9095b5fdba81b366062 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Sun, 24 Jul 2022 12:53:50 +0300 Subject: [PATCH 2/3] Update test/parallel/test-runner-misc.js Co-authored-by: Antoine du Hamel --- test/parallel/test-runner-misc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-runner-misc.js b/test/parallel/test-runner-misc.js index 2834b9833bdc87..694c9685f347ea 100644 --- a/test/parallel/test-runner-misc.js +++ b/test/parallel/test-runner-misc.js @@ -18,7 +18,7 @@ if (process.argv[2] === 'child') { assert.strictEqual(signal.aborted, false); testSignal = signal; await setTimeout(50); - })).then(() => { + })).finally(common.mustCall(() => { test(() => assert.strictEqual(testSignal.aborted, true)); }); } else assert.fail('unreachable'); From aa51f7afb6330bb8c671e099ce1aae2a7e085d64 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Sun, 24 Jul 2022 13:18:45 +0300 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Antoine du Hamel --- test/parallel/test-runner-misc.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-runner-misc.js b/test/parallel/test-runner-misc.js index 694c9685f347ea..34abaf5c120be3 100644 --- a/test/parallel/test-runner-misc.js +++ b/test/parallel/test-runner-misc.js @@ -20,14 +20,14 @@ if (process.argv[2] === 'child') { 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/); - assert.match(stdout, /# fail 0/); - assert.match(stdout, /# cancelled 1/); + 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); }