mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 08:11:42 +00:00
test(perf): speed up supervisor and exec process tests
This commit is contained in:
@@ -25,7 +25,7 @@ describe("runCommandWithTimeout", () => {
|
|||||||
'process.stdout.write((process.env.OPENCLAW_BASE_ENV ?? "") + "|" + (process.env.OPENCLAW_TEST_ENV ?? ""))',
|
'process.stdout.write((process.env.OPENCLAW_BASE_ENV ?? "") + "|" + (process.env.OPENCLAW_TEST_ENV ?? ""))',
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
timeoutMs: 120,
|
timeoutMs: 80,
|
||||||
env: { OPENCLAW_TEST_ENV: "ok" },
|
env: { OPENCLAW_TEST_ENV: "ok" },
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -38,10 +38,10 @@ 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(() => {}, 20)"],
|
[process.execPath, "-e", "setTimeout(() => {}, 10)"],
|
||||||
{
|
{
|
||||||
timeoutMs: 80,
|
timeoutMs: 30,
|
||||||
noOutputTimeoutMs: 8,
|
noOutputTimeoutMs: 4,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -82,9 +82,9 @@ describe("runCommandWithTimeout", () => {
|
|||||||
|
|
||||||
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(() => {}, 12)"],
|
[process.execPath, "-e", "setTimeout(() => {}, 10)"],
|
||||||
{
|
{
|
||||||
timeoutMs: 6,
|
timeoutMs: 4,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,13 @@ 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 = 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) {
|
async function spawnChild(supervisor: ProcessSupervisor, options: ChildSpawnOptions) {
|
||||||
return supervisor.spawn({
|
return supervisor.spawn({
|
||||||
@@ -19,12 +25,7 @@ describe("process supervisor", () => {
|
|||||||
const supervisor = createProcessSupervisor();
|
const supervisor = createProcessSupervisor();
|
||||||
const run = await spawnChild(supervisor, {
|
const run = await spawnChild(supervisor, {
|
||||||
sessionId: "s1",
|
sessionId: "s1",
|
||||||
// Delay stdout slightly so listeners are attached even on heavily loaded runners.
|
argv: createWriteStdoutArgv("ok"),
|
||||||
argv: [
|
|
||||||
process.execPath,
|
|
||||||
"-e",
|
|
||||||
`setTimeout(() => process.stdout.write("ok"), ${OUTPUT_DELAY_MS})`,
|
|
||||||
],
|
|
||||||
timeoutMs: 1_000,
|
timeoutMs: 1_000,
|
||||||
stdinMode: "pipe-closed",
|
stdinMode: "pipe-closed",
|
||||||
});
|
});
|
||||||
@@ -63,12 +64,7 @@ describe("process supervisor", () => {
|
|||||||
sessionId: "s1",
|
sessionId: "s1",
|
||||||
scopeKey: "scope:a",
|
scopeKey: "scope:a",
|
||||||
replaceExistingScope: true,
|
replaceExistingScope: true,
|
||||||
// Small delay makes stdout capture deterministic by giving listeners time to attach.
|
argv: createWriteStdoutArgv("new"),
|
||||||
argv: [
|
|
||||||
process.execPath,
|
|
||||||
"-e",
|
|
||||||
`setTimeout(() => process.stdout.write("new"), ${OUTPUT_DELAY_MS})`,
|
|
||||||
],
|
|
||||||
timeoutMs: 1_000,
|
timeoutMs: 1_000,
|
||||||
stdinMode: "pipe-closed",
|
stdinMode: "pipe-closed",
|
||||||
});
|
});
|
||||||
@@ -98,12 +94,7 @@ describe("process supervisor", () => {
|
|||||||
let streamed = "";
|
let streamed = "";
|
||||||
const run = await spawnChild(supervisor, {
|
const run = await spawnChild(supervisor, {
|
||||||
sessionId: "s-capture",
|
sessionId: "s-capture",
|
||||||
// Avoid race where child exits before stdout listeners are attached.
|
argv: createWriteStdoutArgv("streamed"),
|
||||||
argv: [
|
|
||||||
process.execPath,
|
|
||||||
"-e",
|
|
||||||
`setTimeout(() => process.stdout.write("streamed"), ${OUTPUT_DELAY_MS})`,
|
|
||||||
],
|
|
||||||
timeoutMs: 1_000,
|
timeoutMs: 1_000,
|
||||||
stdinMode: "pipe-closed",
|
stdinMode: "pipe-closed",
|
||||||
captureOutput: false,
|
captureOutput: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user