test(perf): tighten process exec and supervisor timing fixtures

This commit is contained in:
Peter Steinberger
2026-03-02 11:56:57 +00:00
parent 2b855704da
commit d9ff3bf1af
2 changed files with 13 additions and 13 deletions

View File

@@ -38,9 +38,9 @@ describe("runCommandWithTimeout", () => {
it("kills command when no output timeout elapses", async () => {
const result = await runCommandWithTimeout(
[process.execPath, "-e", "setTimeout(() => {}, 30)"],
[process.execPath, "-e", "setTimeout(() => {}, 20)"],
{
timeoutMs: 220,
timeoutMs: 180,
noOutputTimeoutMs: 8,
},
);
@@ -60,15 +60,15 @@ describe("runCommandWithTimeout", () => {
"let count = 0;",
'const ticker = setInterval(() => { process.stdout.write(".");',
"count += 1;",
"if (count === 3) {",
"if (count === 2) {",
"clearInterval(ticker);",
"process.exit(0);",
"}",
"}, 6);",
"}, 5);",
].join(" "),
],
{
timeoutMs: 600,
timeoutMs: 400,
// Keep a healthy margin above the emit interval while avoiding long idle waits.
noOutputTimeoutMs: 60,
},
@@ -77,14 +77,14 @@ describe("runCommandWithTimeout", () => {
expect(result.code ?? 0).toBe(0);
expect(result.termination).toBe("exit");
expect(result.noOutputTimedOut).toBe(false);
expect(result.stdout.length).toBeGreaterThanOrEqual(4);
expect(result.stdout.length).toBeGreaterThanOrEqual(3);
});
it("reports global timeout termination when overall timeout elapses", async () => {
const result = await runCommandWithTimeout(
[process.execPath, "-e", "setTimeout(() => {}, 20)"],
[process.execPath, "-e", "setTimeout(() => {}, 12)"],
{
timeoutMs: 10,
timeoutMs: 8,
},
);

View File

@@ -4,7 +4,7 @@ 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 = 6;
const OUTPUT_DELAY_MS = 3;
async function spawnChild(supervisor: ProcessSupervisor, options: ChildSpawnOptions) {
return supervisor.spawn({
@@ -38,9 +38,9 @@ describe("process supervisor", () => {
const supervisor = createProcessSupervisor();
const run = await spawnChild(supervisor, {
sessionId: "s1",
argv: [process.execPath, "-e", "setTimeout(() => {}, 18)"],
argv: [process.execPath, "-e", "setTimeout(() => {}, 14)"],
timeoutMs: 300,
noOutputTimeoutMs: 6,
noOutputTimeoutMs: 5,
stdinMode: "pipe-closed",
});
const exit = await run.wait();
@@ -54,7 +54,7 @@ describe("process supervisor", () => {
const first = await spawnChild(supervisor, {
sessionId: "s1",
scopeKey: "scope:a",
argv: [process.execPath, "-e", "setTimeout(() => {}, 120)"],
argv: [process.execPath, "-e", "setTimeout(() => {}, 80)"],
timeoutMs: 1_000,
stdinMode: "pipe-open",
});
@@ -84,7 +84,7 @@ describe("process supervisor", () => {
const supervisor = createProcessSupervisor();
const run = await spawnChild(supervisor, {
sessionId: "s-timeout",
argv: [process.execPath, "-e", "setTimeout(() => {}, 20)"],
argv: [process.execPath, "-e", "setTimeout(() => {}, 12)"],
timeoutMs: 1,
stdinMode: "pipe-closed",
});