Skip to content

[Due for payment 2026-06-12] [Due for payment 2026-06-09] [$50] Flaky test: MiddlewareTest › HandleUnusedOptimisticID - fetch call count assertion fails intermittently #90660

Description

@mountiny

Description

Two tests in `tests/unit/MiddlewareTest.ts` are flaky and fail intermittently in CI:

  • `Middleware › HandleUnusedOptimisticID › Request with preexistingReportID` (line 149)
  • `Middleware › HandleUnusedOptimisticID › OpenReport to a chat with preexistingReportID and clean up optimistic participant data` (line 343)

Both fail on the same assertion:

```
expect(global.fetch).toHaveBeenCalledTimes(2)
```

Evidence

Observed in CI run #33684 (attempt 1 failed, attempt 2 passed — confirming this is a flaky/timing issue).

The logs also report a worker teardown leak:

A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks. Active timers can also cause this.

Likely cause

The tests use `waitForNetworkPromises()` / `waitForBatchedUpdates()` before asserting on `global.fetch` call count. A race condition between the `SequentialQueue.unpause()` call and the fetch mock resolution can cause the second fetch to fire after the assertion runs. The worker teardown leak suggests an open handle (timer or promise) that affects subsequent test isolation.

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022054904870462893459
  • Upwork Job ID: 2054904870462893459
  • Last Price Increase: 2026-05-14
Issue OwnerCurrent Issue Owner: @mallenexpensify

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions