Open OmgImAlexis opened 7 years ago
Get-port is working. There need additional checks, cause yarn runs tests in parallel. When you obtain free port mongod needs some time for startup, at this time starts another mongod process on same port which throws error.
You may try https://github.com/nodkz/mongodb-memory-server i spent quite huge amount of time to make it stable working with parallel testing.
The first time it runs it tries port 27017 which was taken before the tests even started. That's what's making me think get-port
isn't doing what it should or at least the way to port is passed to mongodb isn't setup correctly.
Hey! Thanks for reporting this.
If it's trying port 27017 and MongoDB is constantly running before the tests then the issue is likely with get-port not detecting the port in use.
If you don't have a MongoDB server running locally and you are only booting it up using this package
(e.g. via await MongoDBServer.start()
) then @nodkz may have a point; get-port may not be detecting it due to startup times of the MongoDB in-memory server.
This was an early issue for me when developing the package but wasn't an issue later on in its use and development, so I believed it was just a temporary issue at the time. I will try to find some time to diagnose and fix this if that's the case.
If you find out exactly where this is occurring feel free to submit a PR or let me know and I can fix.
Looks like get-port
can't detect MongoDB and/or docker.
Added this to x.js
.
const getPort = require('get-port');
getPort(27017).then(console.log);
Then ran this and even though mongo is using 27017
getPort returns 27017
.
docker run -p 27017:27017 mongodb
node x.js
When using this if I have mongodb running on port 27017 it still tries binding to that port instead of trying another open port.
For example when using ava with
MongoDBServer.debug = true;
.