Skip to content

Commit b0e37b7

Browse files
addaleaxcodebytere
authored andcommitted
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: #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>
1 parent c34872e commit b0e37b7

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

test/pseudo-tty/test-trace-sigint-on-idle.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
2-
3-
const { mustCall } = require('../common');
2+
const { platformTimeout, mustCall } = require('../common');
43
const childProcess = require('child_process');
54
const assert = require('assert');
65

@@ -14,9 +13,11 @@ if (process.env.CHILD === 'true') {
1413
['--trace-sigint', __filename],
1514
{
1615
env: { ...process.env, CHILD: 'true' },
17-
stdio: 'inherit'
16+
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
1817
});
19-
setTimeout(() => cp.kill('SIGINT'), 1 * 1000);
18+
cp.on('message', mustCall(() => {
19+
setTimeout(() => cp.kill('SIGINT'), platformTimeout(100));
20+
}));
2021
cp.on('exit', mustCall((code, signal) => {
2122
assert.strictEqual(signal, 'SIGINT');
2223
assert.strictEqual(code, null);
@@ -26,5 +27,6 @@ if (process.env.CHILD === 'true') {
2627
function main() {
2728
// Deactivate colors even if the tty does support colors.
2829
process.env.NODE_DISABLE_COLORS = '1';
29-
setTimeout(() => {}, 10 * 1000);
30+
process.channel.ref(); // Keep event loop alive until the signal is received.
31+
process.send('ready');
3032
}

0 commit comments

Comments
 (0)