[NO QA] Fix flaky MiddlewareTest by using resetQueue() in beforeEach#87945
[NO QA] Fix flaky MiddlewareTest by using resetQueue() in beforeEach#87945
Conversation
Replace SequentialQueue.pause() with SequentialQueue.resetQueue() in beforeEach to fully reset queue state (isSequentialQueueRunning, currentRequestPromise, isReadyPromise) between tests. This prevents in-flight requests from a previous test leaking into the next test, which caused intermittent fetch call count mismatches. Co-authored-by: Situ Chandra Shil <situchan@users.noreply.github.com>
| await Onyx.clear(); | ||
| await waitForBatchedUpdates(); | ||
| SequentialQueue.pause(); | ||
| SequentialQueue.resetQueue(); |
There was a problem hiding this comment.
@MelvinBot is pause() redundant in favor of resetQueue()?
There was a problem hiding this comment.
@/tmp/melvinbot-response.md
|
The only failing checks are the PR Author/Reviewer Checklists, which are expected to fail until manually completed. All code checks (ESLint, Prettier, typecheck, spellcheck, all 8 test shards, Storybook) are passing. |
|
They're not redundant — they have opposite effects on
The PR replaces "freeze the queue" ( |
|
@MelvinBot complete author checklist (check off all items) and ready for review |
|
Done — checked off all author checklist items and marked the PR as ready for review. |
|
@MelvinBot mark as ready for review |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / SafariScreen.Recording.2026-04-15.at.9.30.40.AM.mov |
|
We did not find an internal engineer to review this PR, trying to assign a random engineer to #87930 as well as to this PR... Please reach out for help on Slack if no one gets assigned! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f797e552e6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| await Onyx.clear(); | ||
| await waitForBatchedUpdates(); | ||
| SequentialQueue.pause(); | ||
| SequentialQueue.resetQueue(); |
There was a problem hiding this comment.
Keep queue paused during test request setup
Switching beforeEach to SequentialQueue.resetQueue() leaves the queue unpaused, so SequentialQueue.push() can start processing immediately instead of waiting for SequentialQueue.unpause(). In this file, several tests enqueue requests and only then install per-test global.fetch.mockImplementationOnce(...) handlers (for example around the preexistingReportID cases), so the first request can run with the default fetch mock before the custom response is registered, reintroducing timing-dependent failures and incorrect call assertions. This setup previously relied on the queue being paused between enqueue and unpause.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
@situchan we might want both pause and resetQueue?,
There was a problem hiding this comment.
App/src/libs/Network/SequentialQueue.ts
Lines 61 to 69 in 90d893a
pause() only sets isQueuePaused flag to true
Then immediately overwritten to false in resetQueue()
App/src/libs/Network/SequentialQueue.ts
Lines 569 to 577 in 90d893a
There was a problem hiding this comment.
I mean we can reset then pause, but I ran tests multiple times and it seems to work so I guess all good.
|
🚀 Deployed to staging by https://github.com/rlinoz in version: 9.3.60-0 🚀
Bundle Size Analysis (Sentry): |
|
🚀 Deployed to production by https://github.com/mountiny in version: 9.3.60-22 🚀
|
Explanation of Change
The
beforeEachinMiddlewareTest.tscalledSequentialQueue.pause()which only setsisQueuePausedbut does not resetisSequentialQueueRunning,currentRequestPromise, orisReadyPromise. This allowed in-flight requests from a previous test to leak into the next test, causing intermittentfetchcall count mismatches (expected 1, received 3).Replaced
SequentialQueue.pause()withSequentialQueue.resetQueue()which fully resets all internal queue state between tests.resetQueue()already exists specifically for this purpose.Fixed Issues
$ #87930
AI Tests
MiddlewareTest.tstwice consecutively — all 7 tests passed both times, including the previously flaky test "OpenReport to a new chat without preexistingReportID and clean up optimistic participant data"npx prettier --write— no changes needednpx eslint --max-warnings=0— passed with no warningsHuman Tests
Just run tests multiple times to ensure it is not flaky anymore.
QA
NO QA
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.