MongoDb ServerSelectionError Is Thrown Randomly #1180
Replies: 1 comment 1 reply
-
|
Hi @henrychris, considering version 11.5.1 was released 3 months ago, and you say that things suddenly started failing 3 days ago, it suggests an issue with your project/environment, not Testcontainers. If you are getting ECONNREFUSED errors, it suggests the MongoDB container either isn't running or is running but not yet ready to accept connections. You should debug to see what state your container is in at the time your test fails. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using
@testcontainers/mongodbv11.5.1 in Node withmongodbv8.0.12. Starting November 10th, my integration tests began failing randomly with connection errors.Error Messages
Tests fail intermittently with one of these errors:
Test Setup
Jest Configuration (
jest.config.ts):Global Setup (
globalSetup.ts):Integration Setup (
integrationSetup.ts):Environment Configuration (
env.ts):An Example Test
What I've Tried
Moved database connection to app startup: Modified app startup so
databasePluginis called when the tests startup. I also updated the function to read directly fromprocess.env.MONGODB_URIinstead of the cachedenvobject, bypassing potential race conditions with environment variable loading.integrationSetup.tsno longer connects to the database. Tests still failed randomly.Removed default MongoDB URI: Removed the default value from
env.tsand changed.env.testto use a different port (20017) to verify if the default/test config was being used incorrectly. The error still shows127.0.0.1:27017, so this wasn't the issue.I'm not sure what could be the cause, or what to investigate next.
Beta Was this translation helpful? Give feedback.
All reactions