test(perf): speed up supervisor and exec process tests

This commit is contained in:
Peter Steinberger
2026-03-02 13:52:54 +00:00
parent 2d8b8a17ab
commit 09748ab109
2 changed files with 16 additions and 25 deletions

View File

@@ -25,7 +25,7 @@ describe("runCommandWithTimeout", () => {
'process.stdout.write((process.env.OPENCLAW_BASE_ENV ?? "") + "|" + (process.env.OPENCLAW_TEST_ENV ?? ""))',
],
{
timeoutMs: 120,
timeoutMs: 80,
env: { OPENCLAW_TEST_ENV: "ok" },
},
);
@@ -38,10 +38,10 @@ describe("runCommandWithTimeout", () => {
it("kills command when no output timeout elapses", async () => {
const result = await runCommandWithTimeout(
[process.execPath, "-e", "setTimeout(() => {}, 20)"],
[process.execPath, "-e", "setTimeout(() => {}, 10)"],
{
timeoutMs: 80,
noOutputTimeoutMs: 8,
timeoutMs: 30,
noOutputTimeoutMs: 4,
},
);
@@ -82,9 +82,9 @@ describe("runCommandWithTimeout", () => {
it("reports global timeout termination when overall timeout elapses", async () => {
const result = await runCommandWithTimeout(
[process.execPath, "-e", "setTimeout(() => {}, 12)"],
[process.execPath, "-e", "setTimeout(() => {}, 10)"],
{
timeoutMs: 6,
timeoutMs: 4,
},
);

View File

@@ -4,7 +4,13 @@ import { createProcessSupervisor } from "./supervisor.js";
type ProcessSupervisor = ReturnType<typeof createProcessSupervisor>;
type SpawnOptions = Parameters<ProcessSupervisor["spawn"]>[0];
type ChildSpawnOptions = Omit<Extract<SpawnOptions, { mode: "child" }>, "backendId" | "mode">;
const OUTPUT_DELAY_MS = 3;
function createWriteStdoutArgv(output: string): string[] {
if (process.platform === "win32") {
return [process.execPath, "-e", `process.stdout.write(${JSON.stringify(output)})`];
}
return ["/usr/bin/printf", "%s", output];
}
async function spawnChild(supervisor: ProcessSupervisor, options: ChildSpawnOptions) {
return supervisor.spawn({
@@ -19,12 +25,7 @@ describe("process supervisor", () => {
const supervisor = createProcessSupervisor();
const run = await spawnChild(supervisor, {
sessionId: "s1",
// Delay stdout slightly so listeners are attached even on heavily loaded runners.
argv: [
process.execPath,
"-e",
`setTimeout(() => process.stdout.write("ok"), ${OUTPUT_DELAY_MS})`,
],
argv: createWriteStdoutArgv("ok"),
timeoutMs: 1_000,
stdinMode: "pipe-closed",
});
@@ -63,12 +64,7 @@ describe("process supervisor", () => {
sessionId: "s1",
scopeKey: "scope:a",
replaceExistingScope: true,
// Small delay makes stdout capture deterministic by giving listeners time to attach.
argv: [
process.execPath,
"-e",
`setTimeout(() => process.stdout.write("new"), ${OUTPUT_DELAY_MS})`,
],
argv: createWriteStdoutArgv("new"),
timeoutMs: 1_000,
stdinMode: "pipe-closed",
});
@@ -98,12 +94,7 @@ describe("process supervisor", () => {
let streamed = "";
const run = await spawnChild(supervisor, {
sessionId: "s-capture",
// Avoid race where child exits before stdout listeners are attached.
argv: [
process.execPath,
"-e",
`setTimeout(() => process.stdout.write("streamed"), ${OUTPUT_DELAY_MS})`,
],
argv: createWriteStdoutArgv("streamed"),
timeoutMs: 1_000,
stdinMode: "pipe-closed",
captureOutput: false,