fix(tests): resolve flaky fetch count assertions in MiddlewareTest#90724
Closed
ykd007 wants to merge 1 commit into
Closed
fix(tests): resolve flaky fetch count assertions in MiddlewareTest#90724ykd007 wants to merge 1 commit into
ykd007 wants to merge 1 commit into
Conversation
The two HandleUnusedOptimisticID tests were intermittently failing on the assertion that global.fetch was called exactly twice. The root cause is a timing gap between the first request completing, Onyx processing the preexistingReportID update, the middleware updating the second request's data, and the second fetch actually firing. waitForNetworkPromises() alone (which runs 2 batch cycles) was not enough to flush the full async chain. Adding an extra batched-updates and network-promises pass ensures all microtasks and macro-tasks settle before we assert on call counts. Also fixes the 'OpenReport to a chat' test which used only waitForBatchedUpdates() — also insufficient for the same reason. Fixes Expensify#90660
Contributor
|
👋 Hi @ykd007, thanks for your interest in contributing to Expensify! This PR has been automatically closed because it doesn't appear to meet our contribution requirements:
If you'd like to contribute, please make sure to:
Please review our contributing guidelines for more details. If you believe this was closed in error, please reach out in the #expensify-open-source Slack channel. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
/claim #90660
Problem
Two tests in
tests/unit/MiddlewareTest.tswere intermittently failing on:Failures confirmed in CI run #33684 — attempt 1 failed, attempt 2 passed, classic timing flake.
Root Cause
The
HandleUnusedOptimisticIDmiddleware intercepts the first request's response, readspreexistingReportIDout of the Onyx update, then patches the second request's data before it fires. This chain runs across multiple async cycles:waitForNetworkPromises()only covers 2 batch cycles (it'swaitForBatchedUpdates().then(waitForBatchedUpdates)). That's enough for step 2 but not steps 3 and 4. On loaded CI runners, the assertion fires before step 4 completes.The 'OpenReport to a chat' test had the same issue but used only
waitForBatchedUpdates()— even less robust.Fix
Add an extra
waitForBatchedUpdates()+waitForNetworkPromises()pass after the initial wait to fully drain the async queue before asserting on call counts.No logic changes — the tests were conceptually correct, just not waiting long enough.