Repository navigation
Await the initial mongoose connection in MongoDB tests - #1500
Merged
Merged
Conversation
The Atlas Local image restarts mongod at the end of its first-run initialisation, and `runner healthcheck` can pass on the mongod that is about to be stopped. A client connecting straight after `start()` then reached a server that was shutting down. Run the healthcheck twice in the wait strategy: the second check fails or blocks until the final mongod is up. Also await the mongoose initial connection in the MongoDB tests, so a failed first connect fails the test instead of surfacing as an unhandled rejection that Vitest retries cannot absorb.
Running `runner healthcheck` twice only made the early-ready race in the Atlas Local image less likely, so revert the wait strategy change and its simulated regression test. The image exposes no deterministic signal for its final mongod. What remains is the test change: awaiting the mongoose initial connection, so a failed first connect fails the test instead of surfacing as an unhandled rejection. Record in AGENTS.md that odds-reducing changes are not fixes.
…l-ready-race # Conflicts: # AGENTS.md
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The MongoDB tests now await the mongoose initial connection:
mongoose.createConnection(...)becameawait mongoose.createConnection(...).asPromise()in both test files (five calls).createConnection()returns immediately and connects in the background, and mongoose queues operations until the connection is up, so the happy path is unchanged. The difference is when the first connect fails: the background promise used to reject with nothing handling it, so Vitest reported an unhandled rejection and exited 1 even though the retried test passed. Now the error is thrown inside the test, where the CI retry can absorb it.This is what failed
Tests (mongodb, 24.x, docker)in 2 of 92 mongodb jobs across the last 45 Checks runs (jobs 114290620317 and 113776788163): one retried test plus one unhandled rejection.Also adds a rule to
AGENTS.md: a change that only makes a failure less likely (arbitrary delays, repeated checks, more retries) is not a fix.Not changed
The first connect fails in those jobs because the Atlas Local image can report healthy just before it restarts mongod at the end of its first-run initialisation. An earlier revision of this PR ran
runner healthchecktwice to narrow that window; it was dropped because it only reduced the odds. The image exposes no deterministic signal for its final mongod that holds across image builds, so the wait strategy is unchanged.Verification
npm run format,npm run lintnpx vitest run packages/modules/mongodb/srctwice without retries: 10/10 passed, no unhandled errorscreateConnection()against a server that drops every connection makes Vitest report an unhandledMongoServerSelectionError; withasPromise()awaited the rejection is handled.Not breaking
Tests and
AGENTS.mdonly; no change to published code. The docs snippets included from these tests now showawait ...asPromise().