mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 19:44:30 +00:00
perf(test): replace sessions e2e yield loops with waitFor
This commit is contained in:
@@ -30,17 +30,15 @@ vi.mock("../config/config.js", async (importOriginal) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
import "./test-helpers/fast-core-tools.js";
|
import "./test-helpers/fast-core-tools.js";
|
||||||
import { sleep } from "../utils.js";
|
|
||||||
import { createOpenClawTools } from "./openclaw-tools.js";
|
import { createOpenClawTools } from "./openclaw-tools.js";
|
||||||
|
|
||||||
const waitForCalls = async (getCount: () => number, count: number, timeoutMs = 2000) => {
|
const waitForCalls = async (getCount: () => number, count: number, timeoutMs = 2000) => {
|
||||||
const start = Date.now();
|
await vi.waitFor(
|
||||||
while (getCount() < count) {
|
() => {
|
||||||
if (Date.now() - start > timeoutMs) {
|
expect(getCount()).toBeGreaterThanOrEqual(count);
|
||||||
throw new Error(`timed out waiting for ${count} calls`);
|
},
|
||||||
}
|
{ timeout: timeoutMs, interval: 5 },
|
||||||
await sleep(0);
|
);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("sessions tools", () => {
|
describe("sessions tools", () => {
|
||||||
@@ -657,8 +655,12 @@ describe("sessions tools", () => {
|
|||||||
status: "ok",
|
status: "ok",
|
||||||
reply: "initial",
|
reply: "initial",
|
||||||
});
|
});
|
||||||
await sleep(0);
|
await vi.waitFor(
|
||||||
await sleep(0);
|
() => {
|
||||||
|
expect(calls.filter((call) => call.method === "agent")).toHaveLength(4);
|
||||||
|
},
|
||||||
|
{ timeout: 2_000, interval: 5 },
|
||||||
|
);
|
||||||
|
|
||||||
const agentCalls = calls.filter((call) => call.method === "agent");
|
const agentCalls = calls.filter((call) => call.method === "agent");
|
||||||
expect(agentCalls).toHaveLength(4);
|
expect(agentCalls).toHaveLength(4);
|
||||||
|
|||||||
Reference in New Issue
Block a user