test(api-cache): fix flaky cleanup-expired test under coverage instrumentation - #671
Open
fro-bot wants to merge 1 commit into
Open
test(api-cache): fix flaky cleanup-expired test under coverage instrumentation#671fro-bot wants to merge 1 commit into
fro-bot wants to merge 1 commit into
Conversation
…mentation The 'should cleanup only expired entries' test used a 100ms default TTL for all three cache entries, including the 'fresh' entry that should survive cleanupExpired(). Under v8 coverage instrumentation overhead (pnpm test:coverage), the extra time between adding the fresh entry and calling cleanupExpired() could exceed the 100ms TTL, causing the fresh entry to be incorrectly expired (removedEntries: 3 instead of 2). Give the fresh entry a long custom TTL so it can't flake regardless of instrumentation overhead, while the two entries under test still expire via the short default TTL.
This was referenced Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
pnpm test:coveragewas intermittently failing ontest/scripts/api-cache.test.ts > API Cache > Cache Management > should cleanup only expired entrieswithexpected 3 to be 2.pnpm test(no coverage) passed reliably.Root cause
The test used a 100ms default TTL for all three cache entries, including the "fresh" entry that's expected to survive
cleanupExpired(). Under v8 coverage instrumentation overhead, the gap between adding the fresh entry and callingcleanupExpired()could exceed 100ms, causing it to expire too (removedEntries: 3instead of2).Fix
Give the "fresh" entry a long custom TTL (60s) via the existing
set(url, data, ttlMs)override, so it can't flake regardless of instrumentation overhead, while the two entries under test still expire via the short default TTL.Verification
pnpm test:coverage— 57/57 files, 1298/1298 tests passing (previously 1 flaky failure)pnpm test— 57/57 files, 1298/1298 tests passingpnpm lint— 0 errors, 44 pre-existing warnings (unrelated)pnpm build— clean🤖 Filed by Fro Bot autohealing (schedule-95a0d398-29069840394) — category 5 quality gate fix.