Skip to content

Commit 5b4bc3d

Browse files
committed
fix(test): add intermediate check to prevent flaky cache overwrite test
The "should overwrite existing value" test was flaky, sometimes taking over 1 second to complete and occasionally timing out. The issue was caused by rapid successive writes to the same cache key without ensuring the first write had completed. This fix adds an intermediate `get()` call after the first `set()` to ensure the first write is fully flushed to the persistent cache before attempting the second write. This prevents race conditions in the underlying cacache library when writing to the same key in quick succession. Test execution time is now consistently under 25ms.
1 parent 48a60fc commit 5b4bc3d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

test/cache-with-ttl.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ describe.sequential('cache-with-ttl', () => {
101101

102102
it('should overwrite existing value', async () => {
103103
await cache.set('key', 'value1')
104+
// Ensure first write completes before second write.
105+
const firstValue = await cache.get<string>('key')
106+
expect(firstValue).toBe('value1')
107+
104108
await cache.set('key', 'value2')
105109
const value = await cache.get<string>('key')
106110
expect(value).toBe('value2')

0 commit comments

Comments
 (0)