-
-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests that use mongodb replica sets fail on some machines. #911
Comments
This is completely a mongoose error, you are trying to create another model with the same name on the same connection / mongoose instance. Either dont register a new model, or delete the old one first.
Aside from the mongoose specific error, in what context do they happen? (in MMS start / stop, or your operations?)
Quite a old version, did you already try the latest? (currently its |
Yes tried with that one and still got failures of the like
MMS start seems to work fine, we start the server in the It seems to be an issue with knowing when MMS is ready. Is there a way to know when MMS is completely up and running? Not sure if this is exacerbated by the performance of the machines we run our tests on (my local machine in my case). I'm guessing it's a MMS readiness issue which means Mongoose has not got all models setup yet (or possibly a Mongoose issue being not able to figure out when the server is ready) because some of the errors are like:
others come back with The test is a pretty quick one, we just check if an instance has been defined correctly. So it will check that and then quickly call the If I add an arbitrary sleep at the end of the I'll also head to the Mongoose repo and see if people have similar issues there. |
For In case you dont await The only recommendation i can confidently give, is to check that you are using a uneven number for the replset instances (ie 1,3,5,etc), see
If you are using vanilla mongoose, this should not happen, for more debugging there i would need access to the code or representative code examples. Also to further debug the |
@hasezoey thank you so much for you prompt replies, I'll investigate further and test the odd number of server option (I think atm we set the replicas to 2) and also will provide some logs. |
Hello, a bit of a weird one that I cannot really solve.
We use
MongoMemoryReplSet
in our tests and these tests work on some machines and fail on others.Here is the combination of setups we have tested:
I managed to reproduce the issue with a small repo but in that case adding
writeConcern: { wtimeoutMS: 5000}
seems to fix the problem. But it does not in our code base.We are also using NestJS and Mongoose.
We get errors like:
MongoServerError: not primary
MongoServerError: operation was interrupted
OverwriteModelError: Cannot overwrite
collectionOnemodel once compiled.
From what I've noticed it seems to be a timing issue; when using the
MongoMemoryReplSet
mongodb takes longer to startup and so mongoose then takes longer to setup its models, indexes etc. and the tests then fail because we are trying to access the models when they are not ready yet.Are there any special precautions you need to take when using
MongoMemoryReplSet
?Are there any known issues with Mac OS or more recent versions of Node?
I know this is a bit vague but I cannot really share our code and the sample app I did is fixed with the extra parameter (I could share that anyway if needed).
Maybe you can ask me some questions that will then help me look at other options/ideas.
The text was updated successfully, but these errors were encountered: