Skip to content

Commit

Permalink
test_runner: pass signal on timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Jul 20, 2022
1 parent 389b7e1 commit d7b97a2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@ class Test extends AsyncResource {

this.pass();
} catch (err) {
if (err?.code === 'ERR_TEST_FAILURE' && kIsNodeError in err) {
if (err?.code === 'ERR_TEST_FAILURE' && kIsNodeError in err && err.failureType === kTestTimeoutFailure) {
this.cancel(err);
} else if (err?.code === 'ERR_TEST_FAILURE' && kIsNodeError in err) {
this.fail(err);
} else {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
Expand Down
33 changes: 33 additions & 0 deletions test/parallel/test-runner-misc.js
Original file line number Diff line number Diff line change
@@ -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.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
assert.match(stdout, /# pass 1/);
assert.match(stdout, /# fail 0/);
assert.match(stdout, /# cancelled 1/);
}

0 comments on commit d7b97a2

Please sign in to comment.