mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-04 01:34:06 +00:00
test(memory): drive timeout tests with explicit fake clocks
This commit is contained in:
@@ -102,9 +102,10 @@ describe("memory embedding timeout abort", () => {
|
||||
});
|
||||
|
||||
it("aborts the provider operation when the timeout fires", async () => {
|
||||
vi.useFakeTimers();
|
||||
let signalSeen: AbortSignal | undefined;
|
||||
|
||||
await expect(
|
||||
const result = expect(
|
||||
runEmbeddingOperationWithTimeout({
|
||||
timeoutMs: 1,
|
||||
message: "memory embeddings query timed out after 0s",
|
||||
@@ -120,12 +121,15 @@ describe("memory embedding timeout abort", () => {
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow("memory embeddings query timed out after 0s");
|
||||
await vi.advanceTimersByTimeAsync(1);
|
||||
await result;
|
||||
|
||||
expect(signalSeen?.aborted).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps the timeout error when a provider abort listener rejects generically", async () => {
|
||||
await expect(
|
||||
vi.useFakeTimers();
|
||||
const result = expect(
|
||||
runEmbeddingOperationWithTimeout({
|
||||
timeoutMs: 1,
|
||||
message: "memory embeddings batch timed out after 0s",
|
||||
@@ -137,6 +141,8 @@ describe("memory embedding timeout abort", () => {
|
||||
}),
|
||||
}),
|
||||
).rejects.toThrow("memory embeddings batch timed out after 0s");
|
||||
await vi.advanceTimersByTimeAsync(1);
|
||||
await result;
|
||||
});
|
||||
|
||||
it("caps operation watchdog timers before scheduling", async () => {
|
||||
|
||||
@@ -740,6 +740,7 @@ describe("QmdMemoryManager", () => {
|
||||
});
|
||||
|
||||
it("times out collection bootstrap commands", async () => {
|
||||
vi.useFakeTimers();
|
||||
cfg = {
|
||||
...cfg,
|
||||
memory: {
|
||||
@@ -764,7 +765,15 @@ describe("QmdMemoryManager", () => {
|
||||
return createMockChild();
|
||||
});
|
||||
|
||||
const { manager } = await createManager({ mode: "full" });
|
||||
const managerPromise = createManager({ mode: "full" });
|
||||
await waitUntil(() =>
|
||||
spawnMock.mock.calls.some((call: unknown[]) => {
|
||||
const args = call[1] as string[];
|
||||
return args[0] === "collection" && args[1] === "list";
|
||||
}),
|
||||
);
|
||||
await vi.advanceTimersByTimeAsync(15);
|
||||
const { manager } = await managerPromise;
|
||||
const status = manager.status();
|
||||
expect(status.backend).toBe("qmd");
|
||||
expect(status.requestedProvider).toBe("qmd");
|
||||
@@ -4396,6 +4405,7 @@ describe("QmdMemoryManager", () => {
|
||||
});
|
||||
|
||||
it("retries boot update when qmd reports a retryable lock error", async () => {
|
||||
vi.useFakeTimers();
|
||||
cfg = {
|
||||
...cfg,
|
||||
memory: {
|
||||
@@ -4429,26 +4439,14 @@ describe("QmdMemoryManager", () => {
|
||||
return createMockChild();
|
||||
});
|
||||
|
||||
const nativeSetTimeout = globalThis.setTimeout;
|
||||
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout").mockImplementation(((
|
||||
handler: TimerHandler,
|
||||
timeout?: number,
|
||||
...args: unknown[]
|
||||
) => {
|
||||
if (typeof timeout === "number" && timeout >= 500) {
|
||||
return nativeSetTimeout(handler, 1, ...args);
|
||||
}
|
||||
return nativeSetTimeout(handler, timeout, ...args);
|
||||
}) as typeof globalThis.setTimeout);
|
||||
const managerPromise = createManager({ mode: "full" });
|
||||
await waitUntil(() => updateCalls === 1);
|
||||
await vi.advanceTimersByTimeAsync(500);
|
||||
await waitUntil(() => updateCalls === 2);
|
||||
const { manager } = await managerPromise;
|
||||
|
||||
const { manager } = await createManager({ mode: "full" });
|
||||
|
||||
try {
|
||||
expect(updateCalls).toBe(2);
|
||||
await manager.close();
|
||||
} finally {
|
||||
setTimeoutSpy.mockRestore();
|
||||
}
|
||||
expect(updateCalls).toBe(2);
|
||||
await manager.close();
|
||||
});
|
||||
|
||||
it("succeeds on qmd update even when stdout exceeds the output cap", async () => {
|
||||
|
||||
@@ -1169,8 +1169,8 @@ describe("memory plugin e2e", () => {
|
||||
|
||||
test("clamps oversized auto-recall timeout timers", async () => {
|
||||
vi.useFakeTimers();
|
||||
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
|
||||
try {
|
||||
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
|
||||
await expect(
|
||||
testing.runWithTimeout({
|
||||
timeoutMs: Number.MAX_SAFE_INTEGER,
|
||||
@@ -1180,14 +1180,15 @@ describe("memory plugin e2e", () => {
|
||||
|
||||
expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS);
|
||||
} finally {
|
||||
setTimeoutSpy.mockRestore();
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
test("falls back for invalid auto-recall timeout timers", async () => {
|
||||
vi.useFakeTimers();
|
||||
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
|
||||
try {
|
||||
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
|
||||
await expect(
|
||||
testing.runWithTimeout({
|
||||
timeoutMs: Number.NaN,
|
||||
@@ -1197,6 +1198,7 @@ describe("memory plugin e2e", () => {
|
||||
|
||||
expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), 1);
|
||||
} finally {
|
||||
setTimeoutSpy.mockRestore();
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user