Skip to content

Commit 959bf7b

Browse files
committed
fix(test): isolate Google embedding batch timeout
1 parent 18e107f commit 959bf7b

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

‎extensions/google/embedding-batch.test.ts‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ vi.mock("openclaw/plugin-sdk/memory-core-host-engine-embeddings", async (importO
2424
});
2525

2626
afterEach(() => {
27+
vi.useRealTimers();
2728
vi.restoreAllMocks();
2829
vi.unstubAllGlobals();
2930
});
@@ -206,10 +207,9 @@ function makeOversizedResponse(status = 200): {
206207
}
207208

208209
describe("Google embedding-batch bounded JSON reads", () => {
209-
it("clamps polling to the remaining batch timeout", async () => {
210+
it("stops before polling status after the batch timeout expires", async () => {
210211
vi.useFakeTimers();
211212
vi.setSystemTime(0);
212-
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
213213
const fetchMock = stubBatchFetch();
214214

215215
const result = runGeminiEmbeddingBatches({
@@ -222,21 +222,15 @@ describe("Google embedding-batch bounded JSON reads", () => {
222222
timeoutMs: 1_000,
223223
debug: (message) => {
224224
if (message.includes("batches/b-0 pending")) {
225-
vi.setSystemTime(500);
225+
vi.setSystemTime(1_000);
226226
}
227227
},
228228
});
229+
const rejection = captureRejection(result);
229230

230-
for (let attempt = 0; attempt < 100 && setTimeoutSpy.mock.calls.length === 0; attempt++) {
231-
await Promise.resolve();
232-
}
233-
expect(setTimeoutSpy).toHaveBeenCalledTimes(1);
234-
expect(setTimeoutSpy.mock.calls[0]?.[1]).toBe(500);
235-
const rejection = expect(result).rejects.toThrow(
236-
"gemini batch batches/b-0 timed out after 1000ms",
237-
);
238-
await vi.runAllTimersAsync();
239-
await rejection;
231+
await expect(rejection).resolves.toMatchObject({
232+
message: "gemini batch batches/b-0 timed out after 1000ms",
233+
});
240234
expect(
241235
fetchMock.mock.calls.filter(([input]) => fetchInputUrl(input).includes("/batches/")),
242236
).toHaveLength(0);

0 commit comments

Comments
 (0)