test: fix flaky test-vm-sigint-existing-handler · nodejs/node@be73480

2 files changed

lines changed

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);

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