Skip to content

Commit

Permalink
test: fix flaky test-vm-sigint-existing-handler
Browse files Browse the repository at this point in the history
Set the `SIGUSR2` handler before spawning the child process to make sure
the signal is always handled.

Ref: #7854
Fixes: #7981
PR-URL: #7982
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
addaleax committed Aug 8, 2016
1 parent b635f7b commit be73480
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions test/parallel/test-vm-sigint-existing-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-vm-sigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
});

Expand Down

0 comments on commit be73480

Please sign in to comment.