mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 09:11:12 +00:00
test(perf): tighten process exec and supervisor timing fixtures
This commit is contained in:
@@ -38,9 +38,9 @@ describe("runCommandWithTimeout", () => {
|
|||||||
|
|
||||||
it("kills command when no output timeout elapses", async () => {
|
it("kills command when no output timeout elapses", async () => {
|
||||||
const result = await runCommandWithTimeout(
|
const result = await runCommandWithTimeout(
|
||||||
[process.execPath, "-e", "setTimeout(() => {}, 30)"],
|
[process.execPath, "-e", "setTimeout(() => {}, 20)"],
|
||||||
{
|
{
|
||||||
timeoutMs: 220,
|
timeoutMs: 180,
|
||||||
noOutputTimeoutMs: 8,
|
noOutputTimeoutMs: 8,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -60,15 +60,15 @@ describe("runCommandWithTimeout", () => {
|
|||||||
"let count = 0;",
|
"let count = 0;",
|
||||||
'const ticker = setInterval(() => { process.stdout.write(".");',
|
'const ticker = setInterval(() => { process.stdout.write(".");',
|
||||||
"count += 1;",
|
"count += 1;",
|
||||||
"if (count === 3) {",
|
"if (count === 2) {",
|
||||||
"clearInterval(ticker);",
|
"clearInterval(ticker);",
|
||||||
"process.exit(0);",
|
"process.exit(0);",
|
||||||
"}",
|
"}",
|
||||||
"}, 6);",
|
"}, 5);",
|
||||||
].join(" "),
|
].join(" "),
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
timeoutMs: 600,
|
timeoutMs: 400,
|
||||||
// Keep a healthy margin above the emit interval while avoiding long idle waits.
|
// Keep a healthy margin above the emit interval while avoiding long idle waits.
|
||||||
noOutputTimeoutMs: 60,
|
noOutputTimeoutMs: 60,
|
||||||
},
|
},
|
||||||
@@ -77,14 +77,14 @@ describe("runCommandWithTimeout", () => {
|
|||||||
expect(result.code ?? 0).toBe(0);
|
expect(result.code ?? 0).toBe(0);
|
||||||
expect(result.termination).toBe("exit");
|
expect(result.termination).toBe("exit");
|
||||||
expect(result.noOutputTimedOut).toBe(false);
|
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 () => {
|
it("reports global timeout termination when overall timeout elapses", async () => {
|
||||||
const result = await runCommandWithTimeout(
|
const result = await runCommandWithTimeout(
|
||||||
[process.execPath, "-e", "setTimeout(() => {}, 20)"],
|
[process.execPath, "-e", "setTimeout(() => {}, 12)"],
|
||||||
{
|
{
|
||||||
timeoutMs: 10,
|
timeoutMs: 8,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { createProcessSupervisor } from "./supervisor.js";
|
|||||||
type ProcessSupervisor = ReturnType<typeof createProcessSupervisor>;
|
type ProcessSupervisor = ReturnType<typeof createProcessSupervisor>;
|
||||||
type SpawnOptions = Parameters<ProcessSupervisor["spawn"]>[0];
|
type SpawnOptions = Parameters<ProcessSupervisor["spawn"]>[0];
|
||||||
type ChildSpawnOptions = Omit<Extract<SpawnOptions, { mode: "child" }>, "backendId" | "mode">;
|
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) {
|
async function spawnChild(supervisor: ProcessSupervisor, options: ChildSpawnOptions) {
|
||||||
return supervisor.spawn({
|
return supervisor.spawn({
|
||||||
@@ -38,9 +38,9 @@ describe("process supervisor", () => {
|
|||||||
const supervisor = createProcessSupervisor();
|
const supervisor = createProcessSupervisor();
|
||||||
const run = await spawnChild(supervisor, {
|
const run = await spawnChild(supervisor, {
|
||||||
sessionId: "s1",
|
sessionId: "s1",
|
||||||
argv: [process.execPath, "-e", "setTimeout(() => {}, 18)"],
|
argv: [process.execPath, "-e", "setTimeout(() => {}, 14)"],
|
||||||
timeoutMs: 300,
|
timeoutMs: 300,
|
||||||
noOutputTimeoutMs: 6,
|
noOutputTimeoutMs: 5,
|
||||||
stdinMode: "pipe-closed",
|
stdinMode: "pipe-closed",
|
||||||
});
|
});
|
||||||
const exit = await run.wait();
|
const exit = await run.wait();
|
||||||
@@ -54,7 +54,7 @@ describe("process supervisor", () => {
|
|||||||
const first = await spawnChild(supervisor, {
|
const first = await spawnChild(supervisor, {
|
||||||
sessionId: "s1",
|
sessionId: "s1",
|
||||||
scopeKey: "scope:a",
|
scopeKey: "scope:a",
|
||||||
argv: [process.execPath, "-e", "setTimeout(() => {}, 120)"],
|
argv: [process.execPath, "-e", "setTimeout(() => {}, 80)"],
|
||||||
timeoutMs: 1_000,
|
timeoutMs: 1_000,
|
||||||
stdinMode: "pipe-open",
|
stdinMode: "pipe-open",
|
||||||
});
|
});
|
||||||
@@ -84,7 +84,7 @@ describe("process supervisor", () => {
|
|||||||
const supervisor = createProcessSupervisor();
|
const supervisor = createProcessSupervisor();
|
||||||
const run = await spawnChild(supervisor, {
|
const run = await spawnChild(supervisor, {
|
||||||
sessionId: "s-timeout",
|
sessionId: "s-timeout",
|
||||||
argv: [process.execPath, "-e", "setTimeout(() => {}, 20)"],
|
argv: [process.execPath, "-e", "setTimeout(() => {}, 12)"],
|
||||||
timeoutMs: 1,
|
timeoutMs: 1,
|
||||||
stdinMode: "pipe-closed",
|
stdinMode: "pipe-closed",
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user