fix(test): isolate Google embedding batch timeout (#116161)

This commit is contained in:
Vincent Koc
2026-07-30 10:11:29 +08:00
committed by GitHub
parent 82af1bf7d4
commit 0370fce7ff
+7 -13
View File
@@ -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);