Skip to content

Commit 51b251d

Browse files
cjihrigMyles Borins
authored andcommitted
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
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
constassert=require('assert');
4+
constcp=require('child_process');
5+
6+
if(process.argv[2]==='child'){
7+
setInterval(()=>{},1000);
8+
}else{
9+
constexitCode=common.isWindows ? 1 : 0;
10+
constSIGKILL=process.binding('constants').SIGKILL;
11+
12+
functionspawn(killSignal){
13+
constchild=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+
returnchild;
20+
}
21+
22+
// Verify that an error is thrown for unknown signals.
23+
assert.throws(()=>{
24+
spawn('SIG_NOT_A_REAL_SIGNAL');
25+
},/Error:Unknownsignal:SIG_NOT_A_REAL_SIGNAL/);
26+
27+
// Verify that the default kill signal is SIGTERM.
28+
{
29+
constchild=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+
constchild=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+
constchild=spawn(SIGKILL);
46+
47+
assert.strictEqual(typeofSIGKILL,'number');
48+
assert.strictEqual(child.signal,'SIGKILL');
49+
assert.strictEqual(child.options.killSignal,SIGKILL);
50+
}
51+
}

0 commit comments

Comments
(0)