mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
test: fix flaky test-watch-mode-kill-signal-*
Some checks failed
V8 patch update / v8-update (push) Has been cancelled
OpenSSL update / openssl-update (push) Has been cancelled
Timezone update / timezone_update (push) Has been cancelled
License update / update_license (push) Has been cancelled
Find inactive collaborators / find (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Find inactive TSC voting members / find (push) Has been cancelled
Node.js daily job / build-lto (push) Has been cancelled
Run CodeQL / Analyze (cpp) (push) Has been cancelled
Run CodeQL / Analyze (javascript) (push) Has been cancelled
Run CodeQL / Analyze (python) (push) Has been cancelled
Close stalled issues and PRs / stale (push) Has been cancelled
Test internet / test-internet (push) Has been cancelled
Some checks failed
V8 patch update / v8-update (push) Has been cancelled
OpenSSL update / openssl-update (push) Has been cancelled
Timezone update / timezone_update (push) Has been cancelled
License update / update_license (push) Has been cancelled
Find inactive collaborators / find (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Find inactive TSC voting members / find (push) Has been cancelled
Node.js daily job / build-lto (push) Has been cancelled
Run CodeQL / Analyze (cpp) (push) Has been cancelled
Run CodeQL / Analyze (javascript) (push) Has been cancelled
Run CodeQL / Analyze (python) (push) Has been cancelled
Close stalled issues and PRs / stale (push) Has been cancelled
Test internet / test-internet (push) Has been cancelled
After the write triggers a restart of the grandchild, the newly spawned second grandchild can post another 'script ready' message before the stdout from the first grandchild is relayed by the watcher and processed by this parent process to kill the watcher. If we write again and trigger another restart, we can end up in an infinite loop and never receive the stdout of the grandchildren in time. Only write once to verify the first grandchild process receives the expected signal. We don't care about the subsequent grandchild processes. PR-URL: https://github.com/nodejs/node/pull/60443 Refs: https://github.com/nodejs/node/issues/60297 Refs: https://github.com/nodejs/node/pull/60391 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Darshan Sen <raisinten@gmail.com>
This commit is contained in:
parent
e1e0830ae5
commit
fa33ba3f76
12
test/fixtures/kill-signal-for-watch.js
vendored
12
test/fixtures/kill-signal-for-watch.js
vendored
|
|
@ -1,4 +1,10 @@
|
||||||
process.on('SIGTERM', () => { console.log('__SIGTERM received__'); process.exit(); });
|
process.on('SIGTERM', () => {
|
||||||
process.on('SIGINT', () => { console.log('__SIGINT received__'); process.exit(); });
|
console.log(`__SIGTERM received__ ${process.pid}`);
|
||||||
process.send('script ready');
|
process.exit();
|
||||||
|
});
|
||||||
|
process.on('SIGINT', () => {
|
||||||
|
console.log(`__SIGINT received__ ${process.pid}`);
|
||||||
|
process.exit();
|
||||||
|
});
|
||||||
|
process.send(`script ready ${process.pid}`);
|
||||||
setTimeout(() => {}, 100_000);
|
setTimeout(() => {}, 100_000);
|
||||||
|
|
|
||||||
|
|
@ -26,20 +26,37 @@ const child = spawn(
|
||||||
);
|
);
|
||||||
|
|
||||||
let stdout = '';
|
let stdout = '';
|
||||||
|
let firstGrandchildPid;
|
||||||
child.stdout.on('data', (data) => {
|
child.stdout.on('data', (data) => {
|
||||||
stdout += `${data}`;
|
const dataStr = data.toString();
|
||||||
if (/__(SIGINT|SIGTERM) received__/.test(stdout)) {
|
console.log(`[STDOUT] ${dataStr}`);
|
||||||
|
stdout += `${dataStr}`;
|
||||||
|
const match = dataStr.match(/__(SIGINT|SIGTERM) received__ (\d+)/);
|
||||||
|
if (match && match[2] === firstGrandchildPid) {
|
||||||
|
console.log(`[PARENT] Sending kill signal to watcher process: ${child.pid}`);
|
||||||
child.kill();
|
child.kill();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// After the write triggers a restart of the grandchild, the newly spawned second
|
||||||
|
// grandchild can post another 'script ready' message before the stdout from the first
|
||||||
|
// grandchild is relayed by the watcher and processed by this parent process to kill
|
||||||
|
// the watcher. If we write again and trigger another restart, we can
|
||||||
|
// end up in an infinite loop and never receive the stdout of the grandchildren in time.
|
||||||
|
// Only write once to verify the first grandchild process receives the expected signal.
|
||||||
|
// We don't care about the subsequent grandchild processes.
|
||||||
child.on('message', (msg) => {
|
child.on('message', (msg) => {
|
||||||
if (msg === 'script ready') {
|
console.log(`[MESSAGE]`, msg);
|
||||||
|
if (!firstGrandchildPid && typeof msg === 'string') {
|
||||||
|
const match = msg.match(/script ready (\d+)/);
|
||||||
|
if (match) {
|
||||||
|
firstGrandchildPid = match[1]; // This is the first grandchild
|
||||||
writeFileSync(indexPath, indexContents);
|
writeFileSync(indexPath, indexContents);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await once(child, 'exit');
|
await once(child, 'exit');
|
||||||
|
|
||||||
assert.match(stdout, /__SIGTERM received__/);
|
assert.match(stdout, new RegExp(`__SIGTERM received__ ${firstGrandchildPid}`));
|
||||||
assert.doesNotMatch(stdout, /__SIGINT received__/);
|
assert.doesNotMatch(stdout, new RegExp(`__SIGINT received__ ${firstGrandchildPid}`));
|
||||||
|
|
|
||||||
|
|
@ -27,20 +27,40 @@ const child = spawn(
|
||||||
);
|
);
|
||||||
|
|
||||||
let stdout = '';
|
let stdout = '';
|
||||||
|
let firstGrandchildPid;
|
||||||
child.stdout.on('data', (data) => {
|
child.stdout.on('data', (data) => {
|
||||||
stdout += `${data}`;
|
const dataStr = data.toString();
|
||||||
if (/__(SIGINT|SIGTERM) received__/.test(stdout)) {
|
console.log(`[STDOUT] ${dataStr}`);
|
||||||
|
stdout += `${dataStr}`;
|
||||||
|
const match = dataStr.match(/__(SIGINT|SIGTERM) received__ (\d+)/);
|
||||||
|
if (match && match[2] === firstGrandchildPid) {
|
||||||
|
console.log(`[PARENT] Sending kill signal to watcher process: ${child.pid}`);
|
||||||
child.kill();
|
child.kill();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// After the write triggers a restart of the grandchild, the newly spawned second
|
||||||
|
// grandchild can post another 'script ready' message before the stdout from the first
|
||||||
|
// grandchild is relayed by the watcher and processed by this parent process to kill
|
||||||
|
// the watcher. If we write again and trigger another restart, we can
|
||||||
|
// end up in an infinite loop and never receive the stdout of the grandchildren in time.
|
||||||
|
// Only write once to verify the first grandchild process receives the expected signal.
|
||||||
|
// We don't care about the subsequent grandchild processes.
|
||||||
child.on('message', (msg) => {
|
child.on('message', (msg) => {
|
||||||
if (msg === 'script ready') {
|
console.log(`[MESSAGE]`, msg);
|
||||||
|
if (!firstGrandchildPid && typeof msg === 'string') {
|
||||||
|
const match = msg.match(/script ready (\d+)/);
|
||||||
|
if (match) {
|
||||||
|
firstGrandchildPid = match[1]; // This is the first grandchild
|
||||||
writeFileSync(indexPath, indexContents);
|
writeFileSync(indexPath, indexContents);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await once(child, 'exit');
|
await once(child, 'exit');
|
||||||
|
|
||||||
assert.match(stdout, /__SIGINT received__/);
|
// The second grandchild, if there is one, could receive SIGTERM if it's killed as a
|
||||||
assert.doesNotMatch(stdout, /__SIGTERM received__/);
|
// consequence of the parent being killed in this process instead of being killed by the
|
||||||
|
// parent for file changes. Here we only care about the first grandchild.
|
||||||
|
assert.match(stdout, new RegExp(`__SIGINT received__ ${firstGrandchildPid}`));
|
||||||
|
assert.doesNotMatch(stdout, new RegExp(`__SIGTERM received__ ${firstGrandchildPid}`));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user