fix(cursor): avoid waiting on buffering to run aggregation middleware - #16289
Conversation
There was a problem hiding this comment.
Pull request overview
This PR targets CI flakiness around aggregation cursors by changing when aggregation middleware runs relative to collection buffering, and by increasing a test suite timeout to help diagnose slow/buffering-related failures.
Changes:
- Run
pre('aggregate')middleware immediately when creating anAggregationCursor, instead of waiting for the collection buffer to drain. - Increase the Mocha timeout for
aggregate.exec()tests to 15s.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/cursor/aggregationCursor.js | Adjusts aggregation cursor initialization to execute pre aggregate middleware without waiting on collection buffering. |
| test/aggregate.test.js | Increases timeout for aggregate exec tests to reduce/diagnose CI flakes due to slowness/buffering. |
There was a problem hiding this comment.
We have a few flaky runs in the last commit:
https://github.com/Automattic/mongoose/actions/runs/26375366547/job/77634594787?pr=16289
https://github.com/Automattic/mongoose/actions/runs/26375366545/job/77634594737?pr=16289
https://github.com/Automattic/mongoose/actions/runs/26375367241/job/77634596554?pr=16289
Probably worth investigating. Otherwise the code changes LGTM
Summary
I was working on #16284, spotted a potential cause of flaking tests: aggregation cursor waits on buffering to run middleware, which is inconsistent with other places where we run middleware regardless of buffering. That is the likely cause for this test flake.
I also cranked up a timeout to see whether this failure was due to a buffering timeout or just slowness on the MongoDB server.
Examples