-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cp = require('child_process'); | ||
|
||
if (process.argv[2] === 'child') { | ||
setInterval(() => {}, 1000); | ||
} else { | ||
const exitCode = common.isWindows ? 1 : 0; | ||
const SIGKILL = process.binding('constants').SIGKILL; | ||
|
||
function spawn(killSignal) { | ||
const child = cp.spawnSync(process.execPath, | ||
[__filename, 'child'], | ||
{killSignal, timeout: 100}); | ||
|
||
assert.strictEqual(child.status, exitCode); | ||
assert.strictEqual(child.error.code, 'ETIMEDOUT'); | ||
return child; | ||
} | ||
|
||
// Verify that an error is thrown for unknown signals. | ||
assert.throws(() => { | ||
spawn('SIG_NOT_A_REAL_SIGNAL'); | ||
}, /Error: Unknown signal: SIG_NOT_A_REAL_SIGNAL/); | ||
|
||
// Verify that the default kill signal is SIGTERM. | ||
{ | ||
const child = spawn(); | ||
|
||
assert.strictEqual(child.signal, 'SIGTERM'); | ||
assert.strictEqual(child.options.killSignal, undefined); | ||
} | ||
|
||
// Verify that a string signal name is handled properly. | ||
{ | ||
const child = spawn('SIGKILL'); | ||
|
||
assert.strictEqual(child.signal, 'SIGKILL'); | ||
assert.strictEqual(child.options.killSignal, SIGKILL); | ||
} | ||
|
||
// Verify that a numeric signal is handled properly. | ||
{ | ||
const child = spawn(SIGKILL); | ||
|
||
assert.strictEqual(typeof SIGKILL, 'number'); | ||
assert.strictEqual(child.signal, 'SIGKILL'); | ||
assert.strictEqual(child.options.killSignal, SIGKILL); | ||
} | ||
} |