Skip to content

Commit 51b251d

Browse files
cjihrigMyles Borins
authored and
Myles Borins
committed
test: add coverage for spawnSync() killSignal
This commit adds a test for the killSignal option to spawnSync(), and the other sync child process functions by extension. PR-URL: #8960 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent e5d2a95 commit 51b251d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const cp = require('child_process');
5+
6+
if (process.argv[2] === 'child') {
7+
setInterval(() => {}, 1000);
8+
} else {
9+
const exitCode = common.isWindows ? 1 : 0;
10+
const SIGKILL = process.binding('constants').SIGKILL;
11+
12+
function spawn(killSignal) {
13+
const child = cp.spawnSync(process.execPath,
14+
[__filename, 'child'],
15+
{killSignal, timeout: 100});
16+
17+
assert.strictEqual(child.status, exitCode);
18+
assert.strictEqual(child.error.code, 'ETIMEDOUT');
19+
return child;
20+
}
21+
22+
// Verify that an error is thrown for unknown signals.
23+
assert.throws(() => {
24+
spawn('SIG_NOT_A_REAL_SIGNAL');
25+
}, /Error: Unknown signal: SIG_NOT_A_REAL_SIGNAL/);
26+
27+
// Verify that the default kill signal is SIGTERM.
28+
{
29+
const child = spawn();
30+
31+
assert.strictEqual(child.signal, 'SIGTERM');
32+
assert.strictEqual(child.options.killSignal, undefined);
33+
}
34+
35+
// Verify that a string signal name is handled properly.
36+
{
37+
const child = spawn('SIGKILL');
38+
39+
assert.strictEqual(child.signal, 'SIGKILL');
40+
assert.strictEqual(child.options.killSignal, SIGKILL);
41+
}
42+
43+
// Verify that a numeric signal is handled properly.
44+
{
45+
const child = spawn(SIGKILL);
46+
47+
assert.strictEqual(typeof SIGKILL, 'number');
48+
assert.strictEqual(child.signal, 'SIGKILL');
49+
assert.strictEqual(child.options.killSignal, SIGKILL);
50+
}
51+
}

0 commit comments

Comments
 (0)