Skip to content

Commit

Permalink
Merge branch 'master' into pr/jeroen-plug/274
Browse files Browse the repository at this point in the history
  • Loading branch information
nodkz committed Mar 19, 2020
2 parents 61932b1 + 9bd61b9 commit 0a47eed
Show file tree
Hide file tree
Showing 23 changed files with 2,081 additions and 98 deletions.
4 changes: 0 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,4 @@ module.exports = {
jasmine: true,
jest: true,
},
globals: {
Class: true,
Iterator: true,
},
};
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [6.4.0](https://github.com/nodkz/mongodb-memory-server/compare/v6.3.3...v6.4.0) (2020-03-19)


### Bug Fixes

* set timeout per test ([b3f9a10](https://github.com/nodkz/mongodb-memory-server/commit/b3f9a10))


### Features

* add try/catch for reinit of repl set ([ab7f5f6](https://github.com/nodkz/mongodb-memory-server/commit/ab7f5f6))





## [6.3.3](https://github.com/nodkz/mongodb-memory-server/compare/v6.3.2...v6.3.3) (2020-03-11)


### Bug Fixes

* update Dependencies ([#281](https://github.com/nodkz/mongodb-memory-server/issues/281)) ([054cbe5](https://github.com/nodkz/mongodb-memory-server/commit/054cbe5)), closes [#280](https://github.com/nodkz/mongodb-memory-server/issues/280)





## [6.3.2](https://github.com/nodkz/mongodb-memory-server/compare/v6.3.1...v6.3.2) (2020-03-03)


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ const opts = { useMongoClient: true }; // remove this option if you use mongoose
before(async () => {
mongoServer = new MongoMemoryServer();
const mongoUri = await mongoServer.getUri();
await mongoose.connect(mongouri, opts);
await mongoose.connect(mongoUri, opts);
});

after(async () => {
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "6.3.2",
"version": "6.4.0",
"command": {
"publish": {
"allowBranch": [
Expand Down
27 changes: 27 additions & 0 deletions packages/mongodb-memory-server-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [6.4.0](https://github.com/nodkz/mongodb-memory-server/compare/v6.3.3...v6.4.0) (2020-03-19)


### Bug Fixes

* set timeout per test ([b3f9a10](https://github.com/nodkz/mongodb-memory-server/commit/b3f9a10))


### Features

* add try/catch for reinit of repl set ([ab7f5f6](https://github.com/nodkz/mongodb-memory-server/commit/ab7f5f6))





## [6.3.3](https://github.com/nodkz/mongodb-memory-server/compare/v6.3.2...v6.3.3) (2020-03-11)


### Bug Fixes

* update Dependencies ([#281](https://github.com/nodkz/mongodb-memory-server/issues/281)) ([054cbe5](https://github.com/nodkz/mongodb-memory-server/commit/054cbe5)), closes [#280](https://github.com/nodkz/mongodb-memory-server/issues/280)





## [6.3.2](https://github.com/nodkz/mongodb-memory-server/compare/v6.3.1...v6.3.2) (2020-03-03)


Expand Down
42 changes: 27 additions & 15 deletions packages/mongodb-memory-server-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-memory-server-core",
"version": "6.3.2",
"version": "6.4.0",
"description": "MongoDB Server for testing (core package, without autodownload). The server will allow you to connect your favourite ODM or client library to the MongoDB Server and run parallel integration tests isolated from each other.",
"main": "lib/index",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -31,40 +31,52 @@
},
"homepage": "https://github.com/nodkz/mongodb-memory-server",
"devDependencies": {
"@types/jest": "25.1.4",
"@types/mongodb": "3.5.2",
"@types/tar-stream": "^2.1.0",
"@types/yauzl": "^2.9.1",
"rimraf": "^3.0.0"
"@typescript-eslint/eslint-plugin": "2.23.0",
"@typescript-eslint/parser": "2.23.0",
"cross-env": "^7.0.2",
"eslint": "6.8.0",
"eslint-config-prettier": "6.10.0",
"jest": "^25.1.0",
"lerna": "3.20.2",
"mongodb": "3.5.4",
"rimraf": "^3.0.2",
"ts-jest": "^25.2.1",
"typescript": "^3.8.3"
},
"dependencies": {
"@types/cross-spawn": "^6.0.1",
"@types/debug": "^4.1.5",
"@types/dedent": "^0.7.0",
"@types/find-cache-dir": "^2.0.0",
"@types/find-package-json": "^1.1.0",
"@types/find-cache-dir": "^3.2.0",
"@types/find-package-json": "^1.1.1",
"@types/get-port": "^4.0.1",
"@types/lockfile": "^1.0.1",
"@types/md5-file": "^4.0.0",
"@types/mkdirp": "^0.5.2",
"@types/md5-file": "^4.0.1",
"@types/mkdirp": "^1.0.0",
"@types/tmp": "0.1.0",
"@types/uuid": "3.4.6",
"@types/uuid": "7.0.0",
"camelcase": "^5.3.1",
"cross-spawn": "^7.0.1",
"debug": "^4.1.1",
"dedent": "^0.7.0",
"find-cache-dir": "3.2.0",
"find-cache-dir": "3.3.1",
"find-package-json": "^1.2.0",
"get-port": "5.0.0",
"https-proxy-agent": "4.0.0",
"get-port": "5.1.1",
"https-proxy-agent": "5.0.0",
"lockfile": "^1.0.4",
"md5-file": "^4.0.0",
"mkdirp": "^0.5.1",
"mkdirp": "^1.0.3",
"tar-stream": "^2.1.1",
"tmp": "^0.1.0",
"uuid": "^3.3.3",
"yauzl": "^2.10.0"
"uuid": "^7.0.2",
"yauzl": "^2.10.0",
"tmp": "^0.1.0"
},
"optionalDependencies": {
"mongodb": "^3.2.7"
"mongodb": "^3.5.4"
},
"scripts": {
"cleanup": "rimraf tmp lib coverage node_modules/.cache",
Expand Down
17 changes: 16 additions & 1 deletion packages/mongodb-memory-server-core/src/MongoMemoryReplSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
StorageEngineT,
} from './types';
import debug from 'debug';
import { MongoError } from 'mongodb';

const log = debug('MongoMS:MongoMemoryReplSet');

Expand Down Expand Up @@ -259,7 +260,21 @@ export default class MongoMemoryReplSet extends EventEmitter {
...(this.opts.replSet.configSettings || {}),
},
};
await admin.command({ replSetInitiate: rsConfig });
try {
await admin.command({ replSetInitiate: rsConfig });
} catch (e) {
if (e instanceof MongoError && e.errmsg == 'already initialized') {
log(`${e.errmsg}: trying to set old config`);
const { config: oldConfig } = await admin.command({ replSetGetConfig: 1 });
log('got old config:\n', oldConfig);
await admin.command({
replSetReconfig: oldConfig,
force: true,
});
} else {
throw e;
}
}
log('Waiting for replica set to have a PRIMARY member.');
await this._waitForPrimary();
this.emit((this._state = 'running'));
Expand Down
6 changes: 5 additions & 1 deletion packages/mongodb-memory-server-core/src/MongoMemoryServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default class MongoMemoryServer {
this.runningInstance = this._startUpInstance()
.catch((err) => {
if (err.message === 'Mongod shutting down' || err === 'Mongod shutting down') {
log(`Mongodb does not started. Trying to start on another port one more time...`);
log(`Mongodb did not start. Trying to start on another port one more time...`);
if (this.opts.instance && this.opts.instance.port) {
this.opts.instance.port = null;
}
Expand Down Expand Up @@ -136,6 +136,10 @@ export default class MongoMemoryServer {
tmpDir: undefined,
};

if (instOpts.port && instOpts.port != data.port) {
log(`starting with port ${data.port}, since ${instOpts.port} was locked:`, data.port);
}

data.uri = await getUriBase(data.ip, data.port, data.dbName);
if (!data.dbPath) {
data.tmpDir = tmp.dirSync({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import MongoMemoryReplSet from '../MongoMemoryReplSet';
import * as tmp from 'tmp';

let tmpDir: tmp.DirResult;
beforeEach(() => {
tmpDir = tmp.dirSync({ prefix: 'reuse-mongo-mem-', unsafeCleanup: true });
});

afterEach(() => {
tmpDir.removeCallback();
});

const sleep = (ms: number) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};

describe('single-member replica set', () => {
it('should start multiple times', async () => {
const opts: any = {
replSet: {
storageEngine: 'wiredTiger',
},
instanceOpts: [
{
port: 27017,
dbPath: tmpDir.name,
},
],
};

const replSetBefore = new MongoMemoryReplSet(opts);
await replSetBefore.waitUntilRunning();
await replSetBefore.stop();
/**
* get-port has a portlocking-feature that keeps ports locked for
* "a minimum of 15 seconds and a maximum of 30 seconds before being released again"
* https://github.com/sindresorhus/get-port#beware
*/
await sleep(30000);

const replSetAfter = new MongoMemoryReplSet(opts);
await replSetAfter.waitUntilRunning();
await replSetAfter.stop();
}, 600000);
});
7 changes: 1 addition & 6 deletions packages/mongodb-memory-server-core/src/util/MongoBinary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ export default class MongoBinary {
static async getDownloadPath(options: any): Promise<string> {
const { downloadDir, platform, arch, version } = options;
// create downloadDir if not exists
await new Promise((resolve, reject) => {
mkdirp(downloadDir, (err: any) => {
if (err) reject(err);
else resolve();
});
});
await mkdirp(downloadDir);

const lockfile = path.resolve(downloadDir, `${version}.lock`);
// wait lock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import yauzl from 'yauzl';
import MongoBinaryDownloadUrl from './MongoBinaryDownloadUrl';
import { DownloadProgressT } from '../types';
import { LATEST_VERSION } from './MongoBinary';
import HttpsProxyAgent from 'https-proxy-agent';
import { HttpsProxyAgent } from 'https-proxy-agent';
import { promisify } from 'util';
import resolveConfig, { envToBool } from './resolve-config';
import debug from 'debug';
Expand Down
4 changes: 2 additions & 2 deletions packages/mongodb-memory-server-core/src/util/db_util.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import uuid from 'uuid/v4';
import { v4 as uuidv4 } from 'uuid';

/**
* Returns a database name string.
* @param {string} dbName
*/
export function generateDbName(dbName?: string): string {
return dbName || uuid();
return dbName || uuidv4();
}

/**
Expand Down
16 changes: 16 additions & 0 deletions packages/mongodb-memory-server-global-3.4/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [6.4.0](https://github.com/nodkz/mongodb-memory-server/compare/v6.3.3...v6.4.0) (2020-03-19)

**Note:** Version bump only for package mongodb-memory-server-global-3.4





## [6.3.3](https://github.com/nodkz/mongodb-memory-server/compare/v6.3.2...v6.3.3) (2020-03-11)

**Note:** Version bump only for package mongodb-memory-server-global-3.4





## [6.3.2](https://github.com/nodkz/mongodb-memory-server/compare/v6.3.1...v6.3.2) (2020-03-03)

**Note:** Version bump only for package mongodb-memory-server-global-3.4
Expand Down
4 changes: 2 additions & 2 deletions packages/mongodb-memory-server-global-3.4/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-memory-server-global-3.4",
"version": "6.3.2",
"version": "6.4.0",
"mongodb_version": "3.4.20",
"description": "MongoDB Server for testing (auto-download 3.4 version to %HOME/.cache/mongodb-binaries).",
"main": "index.js",
Expand All @@ -22,7 +22,7 @@
"mongomem"
],
"dependencies": {
"mongodb-memory-server": "6.3.2",
"mongodb-memory-server": "6.4.0",
"os": "^0.1.1"
},
"scripts": {
Expand Down
16 changes: 16 additions & 0 deletions packages/mongodb-memory-server-global-3.6/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [6.4.0](https://github.com/nodkz/mongodb-memory-server/compare/v6.3.3...v6.4.0) (2020-03-19)

**Note:** Version bump only for package mongodb-memory-server-global-3.6





## [6.3.3](https://github.com/nodkz/mongodb-memory-server/compare/v6.3.2...v6.3.3) (2020-03-11)

**Note:** Version bump only for package mongodb-memory-server-global-3.6





## [6.3.2](https://github.com/nodkz/mongodb-memory-server/compare/v6.3.1...v6.3.2) (2020-03-03)

**Note:** Version bump only for package mongodb-memory-server-global-3.6
Expand Down
4 changes: 2 additions & 2 deletions packages/mongodb-memory-server-global-3.6/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-memory-server-global-3.6",
"version": "6.3.2",
"version": "6.4.0",
"mongodb_version": "3.6.12",
"description": "MongoDB Server for testing (auto-download 3.6 version to %HOME/.cache/mongodb-binaries).",
"main": "index.js",
Expand All @@ -22,7 +22,7 @@
"mongomem"
],
"dependencies": {
"mongodb-memory-server": "6.3.2",
"mongodb-memory-server": "6.4.0",
"os": "^0.1.1"
},
"scripts": {
Expand Down
Loading

0 comments on commit 0a47eed

Please sign in to comment.