Skip to content

Fix race condition in HandleUnusedOptimisticID flaky tests#90743

Closed
ykd007 wants to merge 1 commit into
Expensify:mainfrom
ykd007:fix/middleware-flaky-test-90660
Closed

Fix race condition in HandleUnusedOptimisticID flaky tests#90743
ykd007 wants to merge 1 commit into
Expensify:mainfrom
ykd007:fix/middleware-flaky-test-90660

Conversation

@ykd007

@ykd007 ykd007 commented May 15, 2026

Copy link
Copy Markdown

Root Cause

The two flaky tests in MiddlewareTest.ts fail because waitForNetworkPromises() resolves before Onyx has fully processed the preexistingReportID update and queued the follow-up fetch. This creates a race where the fetch call-count assertion runs with only 1 call registered instead of 2.

Fix

Added a second await waitForNetworkPromises() call at the relevant assertion points. First invocation resolves the initial request and lets Onyx apply the preexistingReportID side effect; second invocation drains the queued follow-up request — giving us a deterministic count before asserting.

Also cleaned up an open handle warning by ensuring SequentialQueue is paused/unpaused symmetrically in teardown.

$ #90660

The two failing assertions both check fetch call counts after SequentialQueue.unpause().
The second fetch only fires after Onyx processes the first response (preexistingReportID
update), which requires a full batched-update cycle. A single waitForNetworkPromises()
sometimes completes before that Onyx cycle runs, causing the fetch count assertion to
see only 1 call instead of 2.

Awaiting waitForNetworkPromises() twice ensures: first round resolves the initial
request and lets Onyx apply the preexistingReportID; second round waits for the
queued follow-up request to complete.

Fixes Expensify#90660
@github-actions

Copy link
Copy Markdown
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:

  • You are not a member of the Expensify GitHub organization
  • No linked GitHub issue was found in the PR description where you are listed as an assignee
  • No linked GitHub PR was found in the PR description where you are the author or a reviewer

If you'd like to contribute, please make sure to:

  1. Find an open issue you'd like to work on
  2. Get assigned to the issue by following our contribution process
  3. Link the issue in your PR description using the format: $ https://github.com/Expensify/App/issues/<issueID>

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.

@github-actions github-actions Bot closed this May 15, 2026
@github-actions github-actions Bot locked as spam and limited conversation to collaborators May 15, 2026
@melvin-bot melvin-bot Bot requested review from Beamanator and removed request for a team May 15, 2026 01:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant