summaryrefslogtreecommitdiff
path: root/test/parallel/test-vm-sigint.js
diff options
context:
space:
mode:
authorDavidCai <davidcai1993@yahoo.com>2017-02-22 21:35:55 +0800
committerAnna Henningsen <anna@addaleax.net>2017-02-24 01:57:28 +0100
commitc7205ba94197ab98e90e4b867c8a149d434a15c3 (patch)
treeed89385633388f09c02358e075bd272592981102 /test/parallel/test-vm-sigint.js
parent5c1ec6ea67bd46b8bdb37baa82fe8fd455a91a5f (diff)
downloadandroid-node-v8-c7205ba94197ab98e90e4b867c8a149d434a15c3.tar.gz
android-node-v8-c7205ba94197ab98e90e4b867c8a149d434a15c3.tar.bz2
android-node-v8-c7205ba94197ab98e90e4b867c8a149d434a15c3.zip
test: increase coverage of vm
PR-URL: https://github.com/nodejs/node/pull/11377 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/parallel/test-vm-sigint.js')
-rw-r--r--test/parallel/test-vm-sigint.js48
1 files changed, 27 insertions, 21 deletions
diff --git a/test/parallel/test-vm-sigint.js b/test/parallel/test-vm-sigint.js
index 8846338b78..24ad7ab047 100644
--- a/test/parallel/test-vm-sigint.js
+++ b/test/parallel/test-vm-sigint.js
@@ -5,6 +5,11 @@ const vm = require('vm');
const spawn = require('child_process').spawn;
+const methods = [
+ 'runInThisContext',
+ 'runInContext'
+];
+
if (common.isWindows) {
// No way to send CTRL_C_EVENT to processes from JS right now.
common.skip('platform not supported');
@@ -12,31 +17,32 @@ if (common.isWindows) {
}
if (process.argv[2] === 'child') {
- const parent = +process.env.REPL_TEST_PPID;
- assert.ok(parent);
+ const method = process.argv[3];
+ assert.ok(method);
+
+ const script = `process.send('${method}'); while(true) {}`;
+ const args = method === 'runInContext' ?
+ [vm.createContext({ process })] :
+ [];
+ const options = { breakOnSigint: true };
- assert.throws(() => {
- vm.runInThisContext(`process.kill(${parent}, "SIGUSR2"); while(true) {}`, {
- breakOnSigint: true
- });
- }, /Script execution interrupted/);
+ assert.throws(() => { vm[method](script, ...args, options); },
+ /^Error: Script execution interrupted\.$/);
return;
}
-process.env.REPL_TEST_PPID = process.pid;
+for (const method of methods) {
+ const child = spawn(process.execPath, [__filename, 'child', method], {
+ stdio: [null, 'pipe', 'inherit', 'ipc']
+ });
-// Set the `SIGUSR2` handler before spawning the child process to make sure
-// the signal is always handled.
-process.on('SIGUSR2', common.mustCall(() => {
- process.kill(child.pid, 'SIGINT');
-}));
+ child.on('message', common.mustCall(() => {
+ process.kill(child.pid, 'SIGINT');
+ }));
-const child = spawn(process.execPath, [__filename, 'child'], {
- stdio: [null, 'pipe', 'inherit']
-});
-
-child.on('close', common.mustCall((code, signal) => {
- assert.strictEqual(signal, null);
- assert.strictEqual(code, 0);
-}));
+ child.on('close', common.mustCall((code, signal) => {
+ assert.strictEqual(signal, null);
+ assert.strictEqual(code, 0);
+ }));
+}