Skip to content

Commit

Permalink
test: fix flaky test-repl-sigint-nested-eval
Browse files Browse the repository at this point in the history
There is a race condition where process.kill can be sent before the
target is ready to receive the signal.

Fixes: #41123
  • Loading branch information
Trott committed Nov 9, 2022
1 parent 01e673c commit 80ade7f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 0 additions & 2 deletions test/parallel/parallel.status
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ prefix parallel
# sample-test : PASS,FLAKY

[true] # This section applies to all platforms
# https://github.com/nodejs/node/issues/41123
test-repl-sigint-nested-eval: PASS, FLAKY
# https://github.com/nodejs/node/issues/43084
test-worker-http2-stream-terminate: PASS, FLAKY

Expand Down
12 changes: 7 additions & 5 deletions test/parallel/test-repl-sigint-nested-eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const spawn = require('child_process').spawn;

process.env.REPL_TEST_PPID = process.pid;
const child = spawn(process.execPath, [ '-i' ], {
stdio: [null, null, 2]
stdio: [null, null, 2, 'ipc']
});

let stdout = '';
Expand All @@ -22,17 +22,19 @@ child.stdout.on('data', function(c) {
});

child.stdout.once('data', common.mustCall(() => {
process.on('SIGUSR2', common.mustCall(() => {
child.on('message', common.mustCall((msg) => {
assert.strictEqual(msg, 'repl is busy');
process.kill(child.pid, 'SIGINT');
child.stdout.once('data', common.mustCall(() => {
// Make sure REPL still works.
child.stdin.end('"foobar"\n');
}));
}));

child.stdin.write('process.kill(+process.env.REPL_TEST_PPID, "SIGUSR2");' +
'vm.runInThisContext("while(true){}", ' +
'{ breakOnSigint: true });\n');
child.stdin.write(
'vm.runInThisContext("process.send(\'repl is busy\'); while(true){}", ' +
'{ breakOnSigint: true });\n'
);
}));

child.on('close', function(code) {
Expand Down

0 comments on commit 80ade7f

Please sign in to comment.