mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 05:12:43 +00:00
perf(test): speed up subagent persistence e2e flushes
This commit is contained in:
@@ -24,7 +24,9 @@ vi.mock("../infra/agent-events.js", () => ({
|
|||||||
onAgentEvent: vi.fn(() => noop),
|
onAgentEvent: vi.fn(() => noop),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const announceSpy = vi.fn(async () => true);
|
const { announceSpy } = vi.hoisted(() => ({
|
||||||
|
announceSpy: vi.fn(async () => true),
|
||||||
|
}));
|
||||||
vi.mock("./subagent-announce.js", () => ({
|
vi.mock("./subagent-announce.js", () => ({
|
||||||
runSubagentAnnounceFlow: announceSpy,
|
runSubagentAnnounceFlow: announceSpy,
|
||||||
}));
|
}));
|
||||||
@@ -47,27 +49,35 @@ describe("subagent registry persistence", () => {
|
|||||||
childSessionKey: string;
|
childSessionKey: string;
|
||||||
task: string;
|
task: string;
|
||||||
cleanup: "keep" | "delete";
|
cleanup: "keep" | "delete";
|
||||||
}) => ({
|
}) => {
|
||||||
version: 2,
|
const now = Date.now();
|
||||||
runs: {
|
return {
|
||||||
[params.runId]: {
|
version: 2,
|
||||||
runId: params.runId,
|
runs: {
|
||||||
childSessionKey: params.childSessionKey,
|
[params.runId]: {
|
||||||
requesterSessionKey: "agent:main:main",
|
runId: params.runId,
|
||||||
requesterDisplayKey: "main",
|
childSessionKey: params.childSessionKey,
|
||||||
task: params.task,
|
requesterSessionKey: "agent:main:main",
|
||||||
cleanup: params.cleanup,
|
requesterDisplayKey: "main",
|
||||||
createdAt: 1,
|
task: params.task,
|
||||||
startedAt: 1,
|
cleanup: params.cleanup,
|
||||||
endedAt: 2,
|
createdAt: now - 2,
|
||||||
|
startedAt: now - 1,
|
||||||
|
endedAt: now,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
};
|
||||||
});
|
};
|
||||||
|
|
||||||
|
const flushQueuedRegistryWork = async () => {
|
||||||
|
await Promise.resolve();
|
||||||
|
await Promise.resolve();
|
||||||
|
};
|
||||||
|
|
||||||
const restartRegistryAndFlush = async () => {
|
const restartRegistryAndFlush = async () => {
|
||||||
resetSubagentRegistryForTests({ persist: false });
|
resetSubagentRegistryForTests({ persist: false });
|
||||||
initSubagentRegistry();
|
initSubagentRegistry();
|
||||||
await new Promise((r) => setTimeout(r, 0));
|
await flushQueuedRegistryWork();
|
||||||
};
|
};
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
@@ -117,7 +127,7 @@ describe("subagent registry persistence", () => {
|
|||||||
initSubagentRegistry();
|
initSubagentRegistry();
|
||||||
|
|
||||||
// allow queued async wait/cleanup to execute
|
// allow queued async wait/cleanup to execute
|
||||||
await new Promise((r) => setTimeout(r, 0));
|
await flushQueuedRegistryWork();
|
||||||
|
|
||||||
expect(announceSpy).toHaveBeenCalled();
|
expect(announceSpy).toHaveBeenCalled();
|
||||||
|
|
||||||
@@ -169,7 +179,7 @@ describe("subagent registry persistence", () => {
|
|||||||
resetSubagentRegistryForTests({ persist: false });
|
resetSubagentRegistryForTests({ persist: false });
|
||||||
initSubagentRegistry();
|
initSubagentRegistry();
|
||||||
|
|
||||||
await new Promise((r) => setTimeout(r, 0));
|
await flushQueuedRegistryWork();
|
||||||
|
|
||||||
// announce should NOT be called since cleanupHandled was true
|
// announce should NOT be called since cleanupHandled was true
|
||||||
const calls = (announceSpy.mock.calls as unknown as Array<[unknown]>).map((call) => call[0]);
|
const calls = (announceSpy.mock.calls as unknown as Array<[unknown]>).map((call) => call[0]);
|
||||||
|
|||||||
Reference in New Issue
Block a user