mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-08 19:12:22 +00:00
fix(bench): clean timed-out sample process groups
This commit is contained in:
@@ -29,6 +29,15 @@ function withEnv<T>(env: Record<string, string | undefined>, callback: () => T):
|
||||
}
|
||||
}
|
||||
|
||||
function isProcessAlive(pid: number): boolean {
|
||||
try {
|
||||
process.kill(pid, 0);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
describe("bench-cli-startup", () => {
|
||||
it("rejects unknown CLI options before running benchmarks", () => {
|
||||
expect(() => testing.validateCliArgs(["--wat"])).toThrow("Unknown argument: --wat");
|
||||
@@ -49,6 +58,71 @@ describe("bench-cli-startup", () => {
|
||||
expect(result.stderr).not.toContain("\n at ");
|
||||
});
|
||||
|
||||
it.runIf(process.platform !== "win32")(
|
||||
"cleans timed-out benchmark process groups when the leader exits first",
|
||||
() => {
|
||||
const tempDirs = createTempDirTracker();
|
||||
const tmpDir = tempDirs.make("openclaw-cli-startup-timeout-group-");
|
||||
const entryPath = join(tmpDir, "entry.mjs");
|
||||
const childPidPath = join(tmpDir, "child.pid");
|
||||
let childPid = 0;
|
||||
try {
|
||||
writeFileSync(
|
||||
entryPath,
|
||||
[
|
||||
"import { spawn } from 'node:child_process';",
|
||||
"import { writeFileSync } from 'node:fs';",
|
||||
"process.on('SIGTERM', () => process.exit(0));",
|
||||
"const child = spawn(process.execPath, [",
|
||||
" '-e',",
|
||||
" \"process.on('SIGTERM',()=>{});setInterval(()=>{},1000);\",",
|
||||
"], { stdio: 'ignore' });",
|
||||
`writeFileSync(${JSON.stringify(childPidPath)}, String(child.pid));`,
|
||||
"setInterval(() => {}, 1000);",
|
||||
"",
|
||||
].join("\n"),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
const result = spawnSync(
|
||||
process.execPath,
|
||||
[
|
||||
"--import",
|
||||
"tsx",
|
||||
"scripts/bench-cli-startup.ts",
|
||||
"--entry",
|
||||
entryPath,
|
||||
"--case",
|
||||
"version",
|
||||
"--runs",
|
||||
"1",
|
||||
"--warmup",
|
||||
"0",
|
||||
"--timeout-ms",
|
||||
"100",
|
||||
"--json",
|
||||
],
|
||||
{
|
||||
cwd: join(__dirname, "../.."),
|
||||
encoding: "utf8",
|
||||
timeout: 8_000,
|
||||
},
|
||||
);
|
||||
|
||||
childPid = Number(readFileSync(childPidPath, "utf8"));
|
||||
expect(result.status).toBe(1);
|
||||
expect(result.signal).toBeNull();
|
||||
expect(result.stderr).toContain("version sample 1: timed out");
|
||||
expect(isProcessAlive(childPid)).toBe(false);
|
||||
} finally {
|
||||
if (childPid && isProcessAlive(childPid)) {
|
||||
process.kill(childPid, "SIGKILL");
|
||||
}
|
||||
tempDirs.cleanup();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("writes compare-mode JSON output and creates parent directories", () => {
|
||||
const tempDirs = createTempDirTracker();
|
||||
const tmpDir = tempDirs.make("openclaw-cli-startup-compare-output-");
|
||||
|
||||
Reference in New Issue
Block a user