mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
fix(test): isolate Google embedding batch timeout (#116161)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user