From 2fc72cac9795b5e0d9cc1661d05347b4ac48d7ae Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 5 Feb 2020 15:57:47 +0100 Subject: [PATCH] test: fix flaky test-trace-sigint-on-idle Previously, the test could fail on slow machines because the child process was still in the process of starting up after one second, and not yet idle. To resolve this: - Wait for a message from the child process indicating that it had started. - Wait some time after that, but make it platform-dependent to account for timing differences. - Remove the timer in the child process. PR-URL: https://github.com/nodejs/node/pull/31645 Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Richard Lau Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Rich Trott --- test/pseudo-tty/test-trace-sigint-on-idle.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/pseudo-tty/test-trace-sigint-on-idle.js b/test/pseudo-tty/test-trace-sigint-on-idle.js index 398aa8df097d2b..5f79cb82fe95db 100644 --- a/test/pseudo-tty/test-trace-sigint-on-idle.js +++ b/test/pseudo-tty/test-trace-sigint-on-idle.js @@ -1,6 +1,5 @@ 'use strict'; - -const { mustCall } = require('../common'); +const { platformTimeout, mustCall } = require('../common'); const childProcess = require('child_process'); const assert = require('assert'); @@ -14,9 +13,11 @@ if (process.env.CHILD === 'true') { ['--trace-sigint', __filename], { env: { ...process.env, CHILD: 'true' }, - stdio: 'inherit' + stdio: ['inherit', 'inherit', 'inherit', 'ipc'] }); - setTimeout(() => cp.kill('SIGINT'), 1 * 1000); + cp.on('message', mustCall(() => { + setTimeout(() => cp.kill('SIGINT'), platformTimeout(100)); + })); cp.on('exit', mustCall((code, signal) => { assert.strictEqual(signal, 'SIGINT'); assert.strictEqual(code, null); @@ -26,5 +27,6 @@ if (process.env.CHILD === 'true') { function main() { // Deactivate colors even if the tty does support colors. process.env.NODE_DISABLE_COLORS = '1'; - setTimeout(() => {}, 10 * 1000); + process.channel.ref(); // Keep event loop alive until the signal is received. + process.send('ready'); }