diff --git a/test/parallel/test-vm-sigint-existing-handler.js b/test/parallel/test-vm-sigint-existing-handler.js index 0f86b53dd282be..c0ab1f8d92b821 100644 --- a/test/parallel/test-vm-sigint-existing-handler.js +++ b/test/parallel/test-vm-sigint-existing-handler.js @@ -61,16 +61,19 @@ if (process.argv[2] === 'child') { } process.env.REPL_TEST_PPID = process.pid; -const child = spawn(process.execPath, [ __filename, 'child' ], { - stdio: [null, 'inherit', 'inherit'] -}); +// Set the `SIGUSR2` handler before spawning the child process to make sure +// the signal is always handled. process.on('SIGUSR2', common.mustCall(() => { // First kill() breaks the while(true) loop, second one invokes the real // signal handlers. process.kill(child.pid, 'SIGINT'); }, 3)); +const child = spawn(process.execPath, [__filename, 'child'], { + stdio: [null, 'inherit', 'inherit'] +}); + child.on('close', function(code, signal) { assert.strictEqual(signal, null); assert.strictEqual(code, 0); diff --git a/test/parallel/test-vm-sigint.js b/test/parallel/test-vm-sigint.js index 15d61d3232871a..8846338b78086c 100644 --- a/test/parallel/test-vm-sigint.js +++ b/test/parallel/test-vm-sigint.js @@ -25,11 +25,14 @@ if (process.argv[2] === 'child') { } process.env.REPL_TEST_PPID = process.pid; + +// 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'); })); -const child = spawn(process.execPath, [ __filename, 'child' ], { +const child = spawn(process.execPath, [__filename, 'child'], { stdio: [null, 'pipe', 'inherit'] });