Skip to content

Commit e40cc9e

Browse files
committed
test: fix flaky test-watch-mode-kill-signal-*
This should only be triggered once. When the write triggers a restart of the child, the newly spawned child can post another 'script ready' message, and if we write again and trigger another restart we can end up in an infinite loop.
1 parent 3c8c1ef commit e40cc9e

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

test/parallel/parallel.status

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,8 @@ test-cluster-primary-error: PASS, FLAKY
154154
[$arch==loong64]
155155
# https://github.com/nodejs/node/issues/51662
156156
test-http-correct-hostname: SKIP
157+
158+
[$system==macos || $system=win32 || ($system==linux && $arch==s390x) || ($system==linux && $arch==arm64)]
159+
# https://github.com/nodejs/node/issues/60297
160+
test-watch-mode-kill-signal-default: PASS, FLAKY
161+
test-watch-mode-kill-signal-override: PASS, FLAKY

test/parallel/test-watch-mode-kill-signal-default.mjs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,25 @@ const child = spawn(
2727

2828
let stdout = '';
2929
child.stdout.on('data', (data) => {
30-
stdout += `${data}`;
30+
let dataStr = data.toString();
31+
console.log(`[STDOUT] ${dataStr}`);
32+
stdout += `${dataStr}`;
3133
if (/__(SIGINT|SIGTERM) received__/.test(stdout)) {
34+
console.log(`[PARENT] Sending kill signal to child process: ${child.pid}`);
3235
child.kill();
3336
}
3437
});
3538

39+
// This should only be triggered once. When the write triggers a restart of the
40+
// child, the newly spawned child can post another 'script ready' message, and if
41+
// we write again and trigger another restart we can end up in an infinite loop.
42+
let written = false;
3643
child.on('message', (msg) => {
44+
console.log(`[MESSAGE]`, msg);
3745
if (msg === 'script ready') {
46+
if (written) return;
3847
writeFileSync(indexPath, indexContents);
48+
written = true;
3949
}
4050
});
4151

test/parallel/test-watch-mode-kill-signal-override.mjs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,25 @@ const child = spawn(
2828

2929
let stdout = '';
3030
child.stdout.on('data', (data) => {
31-
stdout += `${data}`;
31+
let dataStr = data.toString();
32+
console.log(`[STDOUT] ${dataStr}`);
33+
stdout += `${dataStr}`;
3234
if (/__(SIGINT|SIGTERM) received__/.test(stdout)) {
35+
console.log(`[PARENT] Sending kill signal to child process: ${child.pid}`);
3336
child.kill();
3437
}
3538
});
3639

40+
// This should only be triggered once. When the write triggers a restart of the
41+
// child, the newly spawned child can post another 'script ready' message, and if
42+
// we write again and trigger another restart we can end up in an infinite loop.
43+
let written = false;
3744
child.on('message', (msg) => {
45+
console.log(`[MESSAGE]`, msg);
3846
if (msg === 'script ready') {
47+
if (written) return;
3948
writeFileSync(indexPath, indexContents);
49+
written = true;
4050
}
4151
});
4252

0 commit comments

Comments
 (0)