Fix flaky MiddlewareTest assertions after HandleUnusedOptimisticID rewrites queued request#90762
Closed
ykd007 wants to merge 1 commit into
Closed
Fix flaky MiddlewareTest assertions after HandleUnusedOptimisticID rewrites queued request#90762ykd007 wants to merge 1 commit into
ykd007 wants to merge 1 commit into
Conversation
…eportID handling When HandleUnusedOptimisticID rewrites a pending request after seeing preexistingReportID in the first response, the rewrite goes through an async Onyx.merge round-trip before re-enqueuing. A single waitForNetworkPromises() or waitForBatchedUpdates() resolved before the requeued fetch fired, causing the fetch count assertion to flap. Adding a second waitForNetworkPromises() after the initial flush ensures the re-dispatched request has actually completed before asserting on global.fetch call count.
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.
$ #90660
Root cause
When
HandleUnusedOptimisticIDdetects apreexistingReportIDin the first response, it rewrites the subsequent pending request and re-enqueues it. This rewrite path goes through an asyncOnyx.mergecall before the second fetch fires. A singlewaitForNetworkPromises()/waitForBatchedUpdates()resolves before that second round-trip completes, so thetoHaveBeenCalledTimes(2)assertion occasionally runs when only 1 fetch has happened — the classic timing flap.Fix
Add a second
waitForNetworkPromises()after the initial flush in the two affected tests. This mirrors the standard multi-round-trip pattern used elsewhere in the test suite and ensures the requeued fetch has fully settled before the assertion runs.The teardown worker leak reported in the issue is a downstream symptom of the same open promise — the extra flush also lets the test exit cleanly.
Tests
The two tests from
HandleUnusedOptimisticID:Request with preexistingReportIDOpenReport to a chat with preexistingReportID and clean up optimistic participant data