Skip to content

Commit 09977a9

Browse files
committed
perf(test): overlap restart CLI probes
1 parent b662209 commit 09977a9

1 file changed

Lines changed: 42 additions & 29 deletions

File tree

test/scripts/bench-gateway-restart.test.ts

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Bench Gateway Restart tests cover bench gateway restart script behavior.
2-
import { spawnSync } from "node:child_process";
2+
import { spawn } from "node:child_process";
33
import fs from "node:fs";
44
import { createServer } from "node:http";
55
import os from "node:os";
@@ -20,6 +20,38 @@ import { registerStopChildBehaviorTests } from "./bench-gateway-child-test-suppo
2020

2121
type GatewayRestartIntentDatabase = Pick<OpenClawStateKyselyDatabase, "gateway_restart_intent">;
2222

23+
type BenchCliResult = {
24+
status: number | null;
25+
stderr: string;
26+
stdout: string;
27+
};
28+
29+
function runBenchCli(args: string[]): Promise<BenchCliResult> {
30+
return new Promise((resolve, reject) => {
31+
const child = spawn(
32+
process.execPath,
33+
["--import", "tsx", "scripts/bench-gateway-restart.ts", ...args],
34+
{
35+
cwd: process.cwd(),
36+
env: { ...process.env, NODE_NO_WARNINGS: "1" },
37+
stdio: ["ignore", "pipe", "pipe"],
38+
},
39+
);
40+
let stderr = "";
41+
let stdout = "";
42+
child.stderr.setEncoding("utf8");
43+
child.stdout.setEncoding("utf8");
44+
child.stderr.on("data", (chunk: string) => {
45+
stderr += chunk;
46+
});
47+
child.stdout.on("data", (chunk: string) => {
48+
stdout += chunk;
49+
});
50+
child.once("error", reject);
51+
child.once("close", (status) => resolve({ status, stderr, stdout }));
52+
});
53+
}
54+
2355
function readRestartIntentRow(env: NodeJS.ProcessEnv) {
2456
const { db } = openOpenClawStateDatabase({ env });
2557
const stateDb = getNodeSqliteKysely<GatewayRestartIntentDatabase>(db);
@@ -33,34 +65,15 @@ function readRestartIntentRow(env: NodeJS.ProcessEnv) {
3365
}
3466

3567
describe("gateway restart benchmark script", () => {
36-
let helpResult: ReturnType<typeof spawnSync>;
37-
let unknownArgsResult: ReturnType<typeof spawnSync>;
38-
39-
beforeAll(() => {
40-
helpResult = spawnSync(
41-
process.execPath,
42-
["--import", "tsx", "scripts/bench-gateway-restart.ts", "--help"],
43-
{
44-
cwd: process.cwd(),
45-
encoding: "utf8",
46-
env: {
47-
...process.env,
48-
NODE_NO_WARNINGS: "1",
49-
},
50-
},
51-
);
52-
unknownArgsResult = spawnSync(
53-
process.execPath,
54-
["--import", "tsx", "scripts/bench-gateway-restart.ts", "--wat"],
55-
{
56-
cwd: process.cwd(),
57-
encoding: "utf8",
58-
env: {
59-
...process.env,
60-
NODE_NO_WARNINGS: "1",
61-
},
62-
},
63-
);
68+
let helpResult: BenchCliResult;
69+
let unknownArgsResult: BenchCliResult;
70+
71+
beforeAll(async () => {
72+
// These validation-only processes share no state; overlap their TSX startup cost.
73+
[helpResult, unknownArgsResult] = await Promise.all([
74+
runBenchCli(["--help"]),
75+
runBenchCli(["--wat"]),
76+
]);
6477
});
6578

6679
it("prints help without running benchmark cases", () => {

0 commit comments

Comments
 (0)