From c17ef0e7abc2d68974fdd7d1341373d8659abb46 Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 31 Aug 2026 11:47:43 +0200 Subject: [PATCH] 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. --- src/lib/cache.test.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib/cache.test.ts b/src/lib/cache.test.ts index 0ac37bff96..a4ec8e4e40 100644 --- a/src/lib/cache.test.ts +++ b/src/lib/cache.test.ts @@ -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); });