typegoose / mongodb-memory-server

Manage & spin up mongodb server binaries with zero(or slight) configuration for tests.
https://typegoose.github.io/mongodb-memory-server/
MIT License
2.56k stars 185 forks source link

The download of the mongodb binary is corrupted when using a hoisted dependency in a monorepo #873

Closed oddball closed 3 months ago

oddball commented 3 months ago

Versions

package: mongo-memory-server

What is the Problem?

The download of the mongodb binary is corrupted when using a hoisted dependency in a monorepo

We have a mono repo.

When I have a repo/packages/auth/package.json and do

> cd repo/packages/auth
> npm i
> npm test
# works fine
> ls -lah ~/.cache/mongodb-binaries/mongod-x64-darwin-6.0.14
-rwxr-xr-x  1 oddball  staff   124M May 16 15:56 /Users/oddball/.cache/mongodb-binaries/mongod-x64-darwin-6.0.14

When I have a repo/package.json to where I host the dependencies

> rm -rf ~/.cache/mongodb-binaries/
> cd repo
> npm i
> cd packages/auth
> npm test
...
Downloading MongoDB "6.0.14": 47.3% (28.4mb / 60.1)...
...
 MongoMS:MongoMemoryServer Mongo[unknown]: _startUpInstance threw a Error:  Error: spawn Unknown system error -88
...
# mongodb does not start
# looking at the downloaded binary:
ls -lah ~/.cache/mongodb-binaries/mongod-x64-darwin-6.0.14
-rwxr-xr-x  1 oddball  staff    43M May 17 10:03 /Users/oddball/.cache/mongodb-binaries/mongod-x64-darwin-6.0.14
# We can see that it is to small! it should be 124 MB and is only 43M (and size differs every time)

If I copy a working mongod-x64-darwin-6.0.14 to ~/.cache/mongodb-binaries/ the tests works fine

hasezoey commented 3 months ago

to confirm, you are using package mongodb-memory-server (no suffix like -core or -global), correct?

are you using any custom configuration (environment variables MONGOMS_ or config.mongodbMemoryServer in a package.json or inside the .create call)?

hasezoey commented 3 months ago

i just tired to reproduce this (on linux), and could not get it.

Could you provide a reproduction repository?

oddball commented 3 months ago

I am using mongodb-memory-server, no suffix

No MONGOMS_ variables

I will make a repo that reproduce it. Might take a day..

oddball commented 3 months ago

While creating a repo to reproduce this, I found out that everything is my fault.

I had a

jest.setTimeout(7000);

in a file, and in the hoisted case, it stopped the download before finishing, making the binary corrupt.

In the other case it ran into a

jest.setTimeout(30000);

first, and all was fine.

Sorry for the noise