Mockgoose: prepareStorage don't work
Hi, I use
Header:
const Mockgoose = require('mockgoose').Mockgoose;
const mongoose = require('mongoose');
let mockgoose = new Mockgoose(mongoose);
Before:
before((done) => {
mockgoose.prepareStorage()
.then(() =>
mongoose.connect("mongodb://localhost/testdb", done));
});
Ps: I using mocha and supertest for tests
And reporter this error:
Error: Timeout of 24000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
Ps: This error happen in before method from mocha
Can anyone help me? I checked with example from README and for me its equal.
Tks
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 23
- Comments: 22
Experienced the same issue as OP as well. Managed to get it working by manually specifying a mongodb version. I’m using mongolab with version 3.2.1, so I used 3.2.1 as well for mockgoose now.
Specifying a version is done as follows:
mockgoose.helper.setDbVersion('3.2.1');
Hope this helps!
Also having same issues as OP with
mockgoose.prepareStorage()
never resolving. Using mockgoose@7.3.3 node@6.1.Haven’t been able to find a workaround yet.
Not working on Ubuntu 18.
I’ve debugged through this today and have some insight as to the nature of the issue.
First and foremost, this issue does not appear to occur on Windows. It appears to be specific to Linux distributions. I imagine that would be why the issues are arising in CI implementations as they would be using a Node image built on a Linux distro.
Secondly, the issue appears to arise because the mongo binary is not emitting a specific message to stdout in the latest build. mongodb-prebuilt (which Mongoose depends upon) appears to be seeking the phrase “waiting for connections on port” as its trigger to resolve the promise upon which prepareStorage depends. Until that message is emitted in stdout, the promise is not resolved (nor is it rejected for that matter). When running prepareStorage without a version parameter, v3.5.9-72-g1faf33b is downloaded. This version is NOT emitting the “waiting for connections on port” message, thus the promise is never resolved.
Interestingly, this version reports itself as a “development version of MongoDB” and is “not recommended for production”. I’m not sure if it is intended to download this version when mongodb-prebuilt initializes without a version, but either way, the nature of the actual issue is that it doesn’t emit this message.
I’ve attached a text log of what version 3.2.14 looks like at startup and what the latest version looks like at startup. You can see that 3.2.14 emits the “waiting for connections on port” message while the latest version does not.
I think there are a variety of different ways this problem could possibly be resolved, so I’ll leave this information in the repo maintainer’s hands to take from here. Please let me know if there are any questions.
mongodb 3-2-14 startup.txt
mongodb latest startup.txt
Just a heads up for those using mockgoose on linux.
I was facing the same timeout issues on my CI server even though tests were passing localy. Turned out libcurl wasn’t installed.
sudo apt-get install libcurl3
This solved my issue.
P.S.: Running with DEBUG=* maybe a lot of output but it’s definitely worth it.
Not working on Windows 10 either.
@sjorssnoeren great, but I continue with a new problem (haha). When I pull the mongodb version 3.2.1, I get an status code 403 (Access Denied) and I think that the promise don’t resolve the reject.
Stdout log from
setDbVersion
.Hi,
Thanks for your hard work on the package - love the ability to test mongoose code easily.
I get the same problem as the OP since recently.
Following test script:
Mockgoose counts up to 100% the first time and mongodb is downloaded to
~.mongodb-prebuilt
. But the secondconsole.info(...)
is just never called.Output with DEBUG=* is as follows:
Using mockgoose@7.3.3, the error happens with both node 7.10.0 and 8.1.3.
Tbh, to me it looks like the package is broken - doesn’t work either in CI or locally and even fails for the exact same builds that have worked before.
I really hope you can fix this issue. Let me know if there’s anything I can do.
Thanks.
I found the error https://github.com/winfinit/mongodb-prebuilt/blob/master/src/mongod-helper.ts#L76 prepareStorage completes if mongodb-prebuilt detects a line matching that regex in mongod’s stdout. newer versions don’t print that line