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