Skip to content

Commit

Permalink
fix: tune tmp dir opts, add debug info, add test for 4.0.3
Browse files Browse the repository at this point in the history
Related #89
  • Loading branch information
nodkz committed Oct 25, 2018
1 parent e826566 commit 962fd67
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 1,113 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/node": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
Expand Down
7 changes: 6 additions & 1 deletion src/MongoMemoryServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ export default class MongoMemoryServer {
if (instOpts.dbPath) {
data.dbPath = instOpts.dbPath;
} else {
tmpDir = tmp.dirSync({ prefix: 'mongo-mem-', unsafeCleanup: true });
tmpDir = tmp.dirSync({
prefix: 'mongo-mem-',
unsafeCleanup: true,
discardDescriptor: true,
mode: '0755',
});
data.dbPath = tmpDir.name;
}

Expand Down
7 changes: 5 additions & 2 deletions src/util/MongoBinary.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export default class MongoBinary {
: false,
};

const { downloadDir, platform, arch, version } = Object.assign({}, defaultOptions, opts);

let debug;
if (opts.debug) {
if (opts.debug.call && typeof opts.debug === 'function' && opts.debug.apply) {
Expand All @@ -47,6 +45,11 @@ export default class MongoBinary {
debug = (msg: string) => {}; // eslint-disable-line
}

const options = { ...defaultOptions, ...opts };
debug(`MongoBinary options: ${JSON.stringify(options)}`);

const { downloadDir, platform, arch, version } = options;

if (this.cache[version]) {
debug(`MongoBinary: found cached binary path for ${version}`);
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/util/MongoInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ export default class MongodbInstance {
this.instanceFailed('Data directory not found');
} else if (/shutting down with code/i.test(log)) {
this.instanceFailed('Mongod shutting down');
} else if (/\*\*\*aborting after/i.test(log)) {
this.instanceFailed('Mongod internal error');
}
}
}
11 changes: 11 additions & 0 deletions src/util/__tests__/MongoInstance-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,15 @@ describe('MongoInstance', () => {
await mongod.kill();
expect(isPidRunning(pid)).toBeFalsy();
});

it('should work with mongodb 4.0.3', async () => {
const mongod = await MongoInstance.run({
instance: { port: 27445, dbPath: tmpDir.name },
binary: { version: '4.0.3' },
debug: true,
});
const pid: any = mongod.getPid();
expect(pid).toBeGreaterThan(0);
await mongod.kill();
});
});
Loading

0 comments on commit 962fd67

Please sign in to comment.