mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-25 21:51:12 +00:00
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.
This commit is contained in:
committed by
GitHub
parent
349f78776d
commit
05980207c6
@@ -1107,10 +1107,14 @@ describe("scripts/test-group-report child process guard", () => {
|
||||
let childPid: number | undefined;
|
||||
let runner: ReturnType<typeof spawn> | undefined;
|
||||
try {
|
||||
// Publish the pid via rename so it appears atomically: waitForFile polls
|
||||
// existence only, and a direct writeFileSync leaves an empty-file window
|
||||
// that made the pid parse as NaN (isProcessAlive false) on loaded CI.
|
||||
const childScript = [
|
||||
"const fs = require('node:fs');",
|
||||
"process.on('SIGTERM', () => {});",
|
||||
`fs.writeFileSync(${JSON.stringify(childPidPath)}, String(process.pid));`,
|
||||
`fs.writeFileSync(${JSON.stringify(`${childPidPath}.tmp`)}, String(process.pid));`,
|
||||
`fs.renameSync(${JSON.stringify(`${childPidPath}.tmp`)}, ${JSON.stringify(childPidPath)});`,
|
||||
"setInterval(() => {}, 1000);",
|
||||
].join("\n");
|
||||
const parentScript = [
|
||||
@@ -1133,8 +1137,10 @@ describe("scripts/test-group-report child process guard", () => {
|
||||
cwd: process.cwd(),
|
||||
stdio: ["ignore", "ignore", "pipe"],
|
||||
});
|
||||
await waitForFile(readyPath, 2_000);
|
||||
await waitForFile(childPidPath, 2_000);
|
||||
// Generous poll deadlines: spawning the nested runner/parent/child node
|
||||
// chain can take multiple seconds on loaded CI runners.
|
||||
await waitForFile(readyPath, 10_000);
|
||||
await waitForFile(childPidPath, 10_000);
|
||||
childPid = Number.parseInt(fs.readFileSync(childPidPath, "utf8"), 10);
|
||||
expect(isProcessAlive(childPid)).toBe(true);
|
||||
|
||||
@@ -1144,7 +1150,7 @@ describe("scripts/test-group-report child process guard", () => {
|
||||
code: null,
|
||||
signal: "SIGTERM",
|
||||
});
|
||||
await waitForDead(childPid, 2_000);
|
||||
await waitForDead(childPid, 10_000);
|
||||
} finally {
|
||||
if (runner?.pid && isProcessAlive(runner.pid)) {
|
||||
runner.kill("SIGKILL");
|
||||
|
||||
Reference in New Issue
Block a user