Fix flaky TTL cache test timing

Use a 20ms TTL with a 40ms wait so the expiry window is long enough
for the immediate second read to hit the in-memory cache reliably.
This commit is contained in:
openhands committed 2026-08-31 11:47:43 +02:00
1 parent 903d175f2d
commit c17ef0e7ab
1 file changed
+5 -4
+5 -4
View File
@@ -36,10 +36,11 @@ describe("cached (memory-only, no Redis)", () => {
let count = 0;
const fn = vi.fn(async () => ++count);
const key = `ttl-${Math.random()}`;
expect(await cached(key, 1, fn)).toBe(1);
expect(await cached(key, 1, fn)).toBe(1);
await new Promise((r) => setTimeout(r, 10));
expect(await cached(key, 1, fn)).toBe(2);
const ttl = 20;
expect(await cached(key, ttl, fn)).toBe(1);
expect(await cached(key, ttl, fn)).toBe(1);
await new Promise((r) => setTimeout(r, 40));
expect(await cached(key, ttl, fn)).toBe(2);
expect(fn).toHaveBeenCalledTimes(2);
});