mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
d8fb5c2f1c
Add support for timeout to spawn and fork. Fixes: https://github.com/nodejs/node/issues/27639 PR-URL: https://github.com/nodejs/node/pull/37256 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
const { mustCall } = require('../common');
|
|
const { strictEqual, throws } = require('assert');
|
|
const fixtures = require('../common/fixtures');
|
|
const { spawn } = require('child_process');
|
|
const { getEventListeners } = require('events');
|
|
|
|
const aliveForeverFile = 'child-process-stay-alive-forever.js';
|
|
{
|
|
// Verify default signal + closes
|
|
const cp = spawn(process.execPath, [fixtures.path(aliveForeverFile)], {
|
|
timeout: 5,
|
|
});
|
|
cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGTERM')));
|
|
}
|
|
|
|
{
|
|
// Verify SIGKILL signal + closes
|
|
const cp = spawn(process.execPath, [fixtures.path(aliveForeverFile)], {
|
|
timeout: 6,
|
|
killSignal: 'SIGKILL',
|
|
});
|
|
cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGKILL')));
|
|
}
|
|
|
|
{
|
|
// Verify timeout verification
|
|
throws(() => spawn(process.execPath, [fixtures.path(aliveForeverFile)], {
|
|
timeout: 'badValue',
|
|
}), /ERR_OUT_OF_RANGE/);
|
|
|
|
throws(() => spawn(process.execPath, [fixtures.path(aliveForeverFile)], {
|
|
timeout: {},
|
|
}), /ERR_OUT_OF_RANGE/);
|
|
}
|
|
|
|
{
|
|
// Verify abort signal gets unregistered
|
|
const controller = new AbortController();
|
|
const { signal } = controller;
|
|
const cp = spawn(process.execPath, [fixtures.path(aliveForeverFile)], {
|
|
timeout: 6,
|
|
signal,
|
|
});
|
|
strictEqual(getEventListeners(signal, 'abort').length, 1);
|
|
cp.on('exit', mustCall(() => {
|
|
strictEqual(getEventListeners(signal, 'abort').length, 0);
|
|
}));
|
|
}
|