mirror of
https://github.com/nodejs/node.git
synced 2025-05-11 19:50:13 +00:00

Extend the Linux logic to all POSIX platforms in test-child-process-exec-abortcontroller-promisified. PR-URL: https://github.com/nodejs/node/pull/46276 Fixes: https://github.com/nodejs/build/issues/3154 Refs: https://github.com/nodejs/node/issues/37518 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Beth Griggs <bethanyngriggs@gmail.com> Reviewed-By: Ruy Adorno <ruyadorno@google.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const exec = require('child_process').exec;
|
|
const { promisify } = require('util');
|
|
|
|
const execPromisifed = promisify(exec);
|
|
const invalidArgTypeError = {
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
name: 'TypeError'
|
|
};
|
|
|
|
const waitCommand = common.isWindows ?
|
|
`${process.execPath} -e "setInterval(()=>{}, 99)"` :
|
|
'sleep 2m';
|
|
|
|
{
|
|
const ac = new AbortController();
|
|
const signal = ac.signal;
|
|
const promise = execPromisifed(waitCommand, { signal });
|
|
assert.rejects(promise, /AbortError/, 'post aborted sync signal failed')
|
|
.then(common.mustCall());
|
|
ac.abort();
|
|
}
|
|
|
|
{
|
|
assert.throws(() => {
|
|
execPromisifed(waitCommand, { signal: {} });
|
|
}, invalidArgTypeError);
|
|
}
|
|
|
|
{
|
|
function signal() {}
|
|
assert.throws(() => {
|
|
execPromisifed(waitCommand, { signal });
|
|
}, invalidArgTypeError);
|
|
}
|
|
|
|
{
|
|
const signal = AbortSignal.abort(); // Abort in advance
|
|
const promise = execPromisifed(waitCommand, { signal });
|
|
|
|
assert.rejects(promise, /AbortError/, 'pre aborted signal failed')
|
|
.then(common.mustCall());
|
|
}
|