Skip to content

Commit 0598020

Browse files
authored
test: deflake test-group-report SIGTERM descendant-cleanup test (#109347)
The child published its pid with a non-atomic writeFileSync while the test polled file existence only, so a loaded runner could read an empty pid file (NaN -> isProcessAlive false). Publish the pid via rename and widen the spawn-chain poll deadlines; assertion strength is unchanged.
1 parent 349f787 commit 0598020

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎test/scripts/test-group-report.test.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,10 +1107,14 @@ describe("scripts/test-group-report child process guard", () => {
11071107
let childPid: number | undefined;
11081108
let runner: ReturnType<typeof spawn> | undefined;
11091109
try {
1110+
// Publish the pid via rename so it appears atomically: waitForFile polls
1111+
// existence only, and a direct writeFileSync leaves an empty-file window
1112+
// that made the pid parse as NaN (isProcessAlive false) on loaded CI.
11101113
const childScript = [
11111114
"const fs = require('node:fs');",
11121115
"process.on('SIGTERM', () => {});",
1113-
`fs.writeFileSync(${JSON.stringify(childPidPath)}, String(process.pid));`,
1116+
`fs.writeFileSync(${JSON.stringify(`${childPidPath}.tmp`)}, String(process.pid));`,
1117+
`fs.renameSync(${JSON.stringify(`${childPidPath}.tmp`)}, ${JSON.stringify(childPidPath)});`,
11141118
"setInterval(() => {}, 1000);",
11151119
].join("\n");
11161120
const parentScript = [
@@ -1133,8 +1137,10 @@ describe("scripts/test-group-report child process guard", () => {
11331137
cwd: process.cwd(),
11341138
stdio: ["ignore", "ignore", "pipe"],
11351139
});
1136-
await waitForFile(readyPath, 2_000);
1137-
await waitForFile(childPidPath, 2_000);
1140+
// Generous poll deadlines: spawning the nested runner/parent/child node
1141+
// chain can take multiple seconds on loaded CI runners.
1142+
await waitForFile(readyPath, 10_000);
1143+
await waitForFile(childPidPath, 10_000);
11381144
childPid = Number.parseInt(fs.readFileSync(childPidPath, "utf8"), 10);
11391145
expect(isProcessAlive(childPid)).toBe(true);
11401146

@@ -1144,7 +1150,7 @@ describe("scripts/test-group-report child process guard", () => {
11441150
code: null,
11451151
signal: "SIGTERM",
11461152
});
1147-
await waitForDead(childPid, 2_000);
1153+
await waitForDead(childPid, 10_000);
11481154
} finally {
11491155
if (runner?.pid && isProcessAlive(runner.pid)) {
11501156
runner.kill("SIGKILL");

0 commit comments

Comments
 (0)