From a82ceb81d27a4671979beeba2681209ab79731a0 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 18 Feb 2026 17:48:44 +0000 Subject: [PATCH] perf(test): replace sessions e2e yield loops with waitFor --- .../openclaw-tools.sessions.e2e.test.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/agents/openclaw-tools.sessions.e2e.test.ts b/src/agents/openclaw-tools.sessions.e2e.test.ts index 100e32e7497..d02f0089bb0 100644 --- a/src/agents/openclaw-tools.sessions.e2e.test.ts +++ b/src/agents/openclaw-tools.sessions.e2e.test.ts @@ -30,17 +30,15 @@ vi.mock("../config/config.js", async (importOriginal) => { }); import "./test-helpers/fast-core-tools.js"; -import { sleep } from "../utils.js"; import { createOpenClawTools } from "./openclaw-tools.js"; const waitForCalls = async (getCount: () => number, count: number, timeoutMs = 2000) => { - const start = Date.now(); - while (getCount() < count) { - if (Date.now() - start > timeoutMs) { - throw new Error(`timed out waiting for ${count} calls`); - } - await sleep(0); - } + await vi.waitFor( + () => { + expect(getCount()).toBeGreaterThanOrEqual(count); + }, + { timeout: timeoutMs, interval: 5 }, + ); }; describe("sessions tools", () => { @@ -657,8 +655,12 @@ describe("sessions tools", () => { status: "ok", reply: "initial", }); - await sleep(0); - await sleep(0); + await vi.waitFor( + () => { + expect(calls.filter((call) => call.method === "agent")).toHaveLength(4); + }, + { timeout: 2_000, interval: 5 }, + ); const agentCalls = calls.filter((call) => call.method === "agent"); expect(agentCalls).toHaveLength(4);