Skip to content

Commit 623dda2

Browse files
committed
test(cache-with-ttl): fix flaky TTL refresh test
Increase timing margins to prevent race conditions: - Increase TTL from 200ms to 300ms - Reduce second wait from 120ms to 100ms - Provides 200ms buffer instead of 80ms for more reliable timing
1 parent f703a6b commit 623dda2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

test/cache-with-ttl.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,16 +446,16 @@ describe.sequential('cache-with-ttl', () => {
446446

447447
it('should refresh TTL on set', async () => {
448448
const refreshCache = createTtlCache({
449-
ttl: 200,
449+
ttl: 300,
450450
prefix: 'refresh-cache',
451451
})
452452

453453
await refreshCache.set('key', 'value1')
454454
await new Promise(resolve => setTimeout(resolve, 100))
455455
await refreshCache.set('key', 'value2') // Refresh TTL
456456

457-
await new Promise(resolve => setTimeout(resolve, 120))
458-
// Should still be cached (100 + 120 = 220ms, but TTL refreshed at 100ms)
457+
await new Promise(resolve => setTimeout(resolve, 100))
458+
// Should still be cached (100 + 100 = 200ms, but TTL refreshed at 100ms to 300ms)
459459
expect(await refreshCache.get<string>('key')).toBe('value2')
460460

461461
await refreshCache.clear()

0 commit comments

Comments
 (0)