test: make stale-while-revalidate cache update test deterministic - #5722
Open
mcollina wants to merge 1 commit into
Open
test: make stale-while-revalidate cache update test deterministic#5722mcollina wants to merge 1 commit into
mcollina wants to merge 1 commit into
Conversation
The test relied on a fixed 500ms sleep after triggering background revalidation before asserting the cache had been updated with new data. On slow/loaded CI runners the revalidation round-trip plus cache write can exceed that window, so the assertion intermittently saw the stale 'original-response' instead of 'updated-response'. Replace the fixed sleep with a poll that waits until the cache actually returns the revalidated content, keeping the test deterministic regardless of runner load.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5722 +/- ##
==========================================
- Coverage 93.47% 93.46% -0.01%
==========================================
Files 110 110
Lines 38906 38908 +2
==========================================
Hits 36366 36366
- Misses 2540 2542 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes the flaky
stale-while-revalidate updates cache after background revalidation (receiving new data)test intest/interceptors/cache.js, which intermittently fails on slow CI runners (e.g. macos) withAssertionError: Expected values to be strictly equal: 'original-response' vs 'updated-response'.The test triggered a background revalidation (RFC 5861) and then slept a fixed
500msbefore asserting the cache had been updated with the revalidated content. On loaded runners the revalidation round-trip plus the cache write can take longer than that window, so the cache was still stale when asserted.The fix replaces the fixed sleep with a poll that keeps issuing stale requests until the cache actually returns the updated response (bounded by a 5s deadline). This makes the test deterministic regardless of runner load: repeated stale requests are served from cache (so
requestsToOriginstays 1) and each triggers background revalidation, sorevalidationRequests >= 1confirms revalidation occurred.Verified by:
test/interceptors/*.jssuite (323 tests, 0 failures)