0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-child-process-fork-timeout-kill-signal.js
Nitzan Uziely d8fb5c2f1c child_process: add timeout to spawn and fork
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>
2021-03-19 12:12:41 +01:00

51 lines
1.3 KiB
JavaScript

'use strict';
const { mustCall } = require('../common');
const { strictEqual, throws } = require('assert');
const fixtures = require('../common/fixtures');
const { fork } = require('child_process');
const { getEventListeners } = require('events');
{
// Verify default signal
const cp = fork(fixtures.path('child-process-stay-alive-forever.js'), {
timeout: 5,
});
cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGTERM')));
}
{
// Verify correct signal + closes after at least 4 ms.
const cp = fork(fixtures.path('child-process-stay-alive-forever.js'), {
timeout: 5,
killSignal: 'SIGKILL',
});
cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGKILL')));
}
{
// Verify timeout verification
throws(() => fork(fixtures.path('child-process-stay-alive-forever.js'), {
timeout: 'badValue',
}), /ERR_OUT_OF_RANGE/);
throws(() => fork(fixtures.path('child-process-stay-alive-forever.js'), {
timeout: {},
}), /ERR_OUT_OF_RANGE/);
}
{
// Verify abort signal gets unregistered
const signal = new EventTarget();
signal.aborted = false;
const cp = fork(fixtures.path('child-process-stay-alive-forever.js'), {
timeout: 6,
signal,
});
strictEqual(getEventListeners(signal, 'abort').length, 1);
cp.on('exit', mustCall(() => {
strictEqual(getEventListeners(signal, 'abort').length, 0);
}));
}