fix: Fix flaky cache revalidation tests caused by sub-millisecond max-age#2116
Open
55728 wants to merge 1 commit intocapricorn86:masterfrom
Open
fix: Fix flaky cache revalidation tests caused by sub-millisecond max-age#211655728 wants to merge 1 commit intocapricorn86:masterfrom
55728 wants to merge 1 commit intocapricorn86:masterfrom
Conversation
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.
Problem
The cache revalidation tests in
Fetch.test.tsintermittently fail on CI because they usemax-age=0.0001(0.1 milliseconds) for cache expiry.In
ResponseCache.ts, the cache entry's expiry is calculated as:Later in the same
add()method, the entry is validated:Since
Date.now()has millisecond precision, if even 1ms passes between the expiry calculation and this validation check, the entry is considered expired and removed during insertion. The second fetch then makes a fresh request instead of a cache revalidation, returning the original response headers instead of the 304 revalidation headers.Solution
max-age=0.0001(0.1ms) tomax-age=0.1(100ms) — large enough to survive the cache insertion, small enough to expire within the test's wait periodAffected tests (4 test cases, 9 value sites + 4 wait sites):
Revalidates cache with a "If-Modified-Since" request for a GET response with "Cache-Control" set to a "max-age".Updates cache after a failed revalidation with a "If-Modified-Since" request for a GET response with "Cache-Control" set to a "max-age".Revalidates cache with a "If-None-Match" request for a HEAD response with an "Etag" header.Updates cache after a failed revalidation with a "If-None-Match" request for a GET response with an "Etag" header.Verification
All 103 Fetch tests pass. The same test that was failing on CI in #1910 and #2114 now has sufficient timing margin to pass reliably.