summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2016-10-06 15:50:00 -0400
committercjihrig <cjihrig@gmail.com>2016-10-10 14:31:01 -0400
commit01db04bd304c39f222cf71e5b16e2e26d1bdf8d5 (patch)
tree38e028b8c8285cd82685e2f9f74d9cf68f20a600 /test
parent528c8449e161bf88f9426ccbccbf68a3684a20b5 (diff)
downloadandroid-node-v8-01db04bd304c39f222cf71e5b16e2e26d1bdf8d5.tar.gz
android-node-v8-01db04bd304c39f222cf71e5b16e2e26d1bdf8d5.tar.bz2
android-node-v8-01db04bd304c39f222cf71e5b16e2e26d1bdf8d5.zip
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: https://github.com/nodejs/node/pull/8960 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-child-process-spawnsync-kill-signal.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/parallel/test-child-process-spawnsync-kill-signal.js b/test/parallel/test-child-process-spawnsync-kill-signal.js
new file mode 100644
index 0000000000..8a3c362216
--- /dev/null
+++ b/test/parallel/test-child-process-spawnsync-kill-signal.js
@@ -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').os.signals;
+
+ 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);
+ }
+}