Skip to content

Commit a385277

Browse files
addaleaxcjihrig
authored andcommitted
test: fix flaky test-vm-sigint-existing-handler
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 <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 909254c commit a385277

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

test/parallel/test-vm-sigint-existing-handler.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,19 @@ if (process.argv[2] === 'child') {
6161
}
6262

6363
process.env.REPL_TEST_PPID = process.pid;
64-
const child = spawn(process.execPath, [ __filename, 'child' ], {
65-
stdio: [null, 'inherit', 'inherit']
66-
});
6764

65+
// Set the `SIGUSR2` handler before spawning the child process to make sure
66+
// the signal is always handled.
6867
process.on('SIGUSR2', common.mustCall(() => {
6968
// First kill() breaks the while(true) loop, second one invokes the real
7069
// signal handlers.
7170
process.kill(child.pid, 'SIGINT');
7271
}, 3));
7372

73+
const child = spawn(process.execPath, [__filename, 'child'], {
74+
stdio: [null, 'inherit', 'inherit']
75+
});
76+
7477
child.on('close', function(code, signal) {
7578
assert.strictEqual(signal, null);
7679
assert.strictEqual(code, 0);

test/parallel/test-vm-sigint.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ if (process.argv[2] === 'child') {
2525
}
2626

2727
process.env.REPL_TEST_PPID = process.pid;
28+
29+
// Set the `SIGUSR2` handler before spawning the child process to make sure
30+
// the signal is always handled.
2831
process.on('SIGUSR2', common.mustCall(() => {
2932
process.kill(child.pid, 'SIGINT');
3033
}));
3134

32-
const child = spawn(process.execPath, [ __filename, 'child' ], {
35+
const child = spawn(process.execPath, [__filename, 'child'], {
3336
stdio: [null, 'pipe', 'inherit']
3437
});
3538

0 commit comments

Comments
 (0)