Replies: 1 comment
-
this is to be expected, especially for repl-sets, because each another reason on why i dont recommend it is because of the lack of port locking, see #827 for some more info
i am not sure why you would still get
without logs and use-case i cannot say much in-detail but this may be related that the instance(s) are "overloaded" (depending on your machine and number of tests and complexity running) or I/O bound (when using |
Beta Was this translation helpful? Give feedback.
-
Wanted to know if there were any downsides to this approach as well as what I am missing in implementing unique tests appropriately. I've been trying to optimize our test suite runtime to see how fast I can have it run through all the tests. We are using nextjs + jest + mongodb-memory-server (v 9.1.3)
Note that each test has been written to assume the db is starting from the same state.
Originally, I had on setup() for each test call a dbConnect() function which basically does a
However, I realized that every call to MongoMemoryReplSet.create() was taking about ~125-150ms for each test. So I was thinking of alternative approaches and thought to try using a global method per recommended in the docs
Then in dbConnect() basically mongoose.connect to
process.env.MONGODB_TEST_URI
However, the issue I had is that the db isn't actually cleared out between each run. When I tried to dropDatabase() right after connect() the issue was that parallel tests that were running would crossover on top of each other (i.e. setting maxWorkers to 2 or more)
I came up with a hack which kind of works (though I get sometimes flaky
port is in use
as well asrandom test timeouts
)Basically the idea is that each test gets their own 'database' to test with... So they don't overlap with each other. The good news is that the tests definitely run faster now (a decent ~15% off our test suite time) -
However, as I mentioned I still sometimes (like 1/6 times maybe) get random tests that just... "hang" and timeout. So I feel that I missed doing this the correct way.
Beta Was this translation helpful? Give feedback.
All reactions