Skip to content

Commit

Permalink
test: fix flaky test-trace-sigint-on-idle
Browse files Browse the repository at this point in the history
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: #31645
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
addaleax authored and codebytere committed Feb 17, 2020
1 parent c34872e commit b0e37b7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions test/pseudo-tty/test-trace-sigint-on-idle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const { mustCall } = require('../common');
const { platformTimeout, mustCall } = require('../common');
const childProcess = require('child_process');
const assert = require('assert');

Expand All @@ -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);
Expand All @@ -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');
}

0 comments on commit b0e37b7

Please sign in to comment.