From 0370fce7ff141cd9d0ee784ba5f7f424f1d50cbd Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Thu, 30 Jul 2026 10:11:29 +0800 Subject: [PATCH] fix(test): isolate Google embedding batch timeout (#116161) --- extensions/google/embedding-batch.test.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/extensions/google/embedding-batch.test.ts b/extensions/google/embedding-batch.test.ts index 65f43ac2324f..7764e2b96d35 100644 --- a/extensions/google/embedding-batch.test.ts +++ b/extensions/google/embedding-batch.test.ts @@ -24,6 +24,7 @@ vi.mock("openclaw/plugin-sdk/memory-core-host-engine-embeddings", async (importO }); afterEach(() => { + vi.useRealTimers(); vi.restoreAllMocks(); vi.unstubAllGlobals(); }); @@ -206,10 +207,9 @@ function makeOversizedResponse(status = 200): { } describe("Google embedding-batch bounded JSON reads", () => { - it("clamps polling to the remaining batch timeout", async () => { + it("stops before polling status after the batch timeout expires", async () => { vi.useFakeTimers(); vi.setSystemTime(0); - const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout"); const fetchMock = stubBatchFetch(); const result = runGeminiEmbeddingBatches({ @@ -222,21 +222,15 @@ describe("Google embedding-batch bounded JSON reads", () => { timeoutMs: 1_000, debug: (message) => { if (message.includes("batches/b-0 pending")) { - vi.setSystemTime(500); + vi.setSystemTime(1_000); } }, }); + const rejection = captureRejection(result); - for (let attempt = 0; attempt < 100 && setTimeoutSpy.mock.calls.length === 0; attempt++) { - await Promise.resolve(); - } - expect(setTimeoutSpy).toHaveBeenCalledTimes(1); - expect(setTimeoutSpy.mock.calls[0]?.[1]).toBe(500); - const rejection = expect(result).rejects.toThrow( - "gemini batch batches/b-0 timed out after 1000ms", - ); - await vi.runAllTimersAsync(); - await rejection; + await expect(rejection).resolves.toMatchObject({ + message: "gemini batch batches/b-0 timed out after 1000ms", + }); expect( fetchMock.mock.calls.filter(([input]) => fetchInputUrl(input).includes("/batches/")), ).toHaveLength(0);