From 4fe5c4e167a3019fde6d16387884643796057bee Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 12 Nov 2022 18:56:08 -0800 Subject: [PATCH] test: fix flaky test-repl-sigint-nested-eval MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is a race condition where process.kill can be sent before the target is ready to receive the signal. Fixes: https://github.com/nodejs/node/issues/41123 PR-URL: https://github.com/nodejs/node/pull/45354 Reviewed-By: Luigi Pinca Reviewed-By: Antoine du Hamel Reviewed-By: Tobias Nießen Reviewed-By: Benjamin Gruenbaum --- test/parallel/parallel.status | 2 -- test/parallel/test-repl-sigint-nested-eval.js | 13 +++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/test/parallel/parallel.status b/test/parallel/parallel.status index b749eb8497743f..ac0ac19f14401c 100644 --- a/test/parallel/parallel.status +++ b/test/parallel/parallel.status @@ -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 diff --git a/test/parallel/test-repl-sigint-nested-eval.js b/test/parallel/test-repl-sigint-nested-eval.js index 28e4d44b235cde..62eb46e0af6759 100644 --- a/test/parallel/test-repl-sigint-nested-eval.js +++ b/test/parallel/test-repl-sigint-nested-eval.js @@ -10,9 +10,8 @@ if (!common.isMainThread) const assert = require('assert'); 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 = ''; @@ -22,7 +21,8 @@ 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. @@ -30,9 +30,10 @@ child.stdout.once('data', common.mustCall(() => { })); })); - 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) {