2020-07-07 23:14:00 +02:00
|
|
|
'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'
|
|
|
|
};
|
|
|
|
|
2023-01-22 11:25:28 +00:00
|
|
|
const waitCommand = common.isWindows ?
|
|
|
|
`${process.execPath} -e "setInterval(()=>{}, 99)"` :
|
|
|
|
'sleep 2m';
|
2020-07-07 23:14:00 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
const ac = new AbortController();
|
|
|
|
const signal = ac.signal;
|
2021-02-11 20:59:00 +02:00
|
|
|
const promise = execPromisifed(waitCommand, { signal });
|
|
|
|
assert.rejects(promise, /AbortError/, 'post aborted sync signal failed')
|
|
|
|
.then(common.mustCall());
|
2020-07-07 23:14:00 +02:00
|
|
|
ac.abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
assert.throws(() => {
|
2021-02-11 20:59:00 +02:00
|
|
|
execPromisifed(waitCommand, { signal: {} });
|
2020-07-07 23:14:00 +02:00
|
|
|
}, invalidArgTypeError);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
function signal() {}
|
|
|
|
assert.throws(() => {
|
2021-02-11 20:59:00 +02:00
|
|
|
execPromisifed(waitCommand, { signal });
|
2020-07-07 23:14:00 +02:00
|
|
|
}, invalidArgTypeError);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-03-18 17:52:08 +01:00
|
|
|
const signal = AbortSignal.abort(); // Abort in advance
|
2021-02-11 20:59:00 +02:00
|
|
|
const promise = execPromisifed(waitCommand, { signal });
|
2020-07-07 23:14:00 +02:00
|
|
|
|
2021-02-11 20:59:00 +02:00
|
|
|
assert.rejects(promise, /AbortError/, 'pre aborted signal failed')
|
|
|
|
.then(common.mustCall());
|
2020-07-07 23:14:00 +02:00
|
|
|
}
|