Socket
Socket
Sign inDemoInstall

mongodb-memory-server-core

Package Overview
Dependencies
Maintainers
1
Versions
273
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-memory-server-core - npm Package Compare versions

Comparing version 5.1.9 to 5.1.10

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

## [5.1.10](https://github.com/nodkz/mongodb-memory-server/compare/v5.1.9...v5.1.10) (2019-08-02)
### Bug Fixes
* **ReplicaSet:** detect primary from stdout instead of admin call ([c081ece](https://github.com/nodkz/mongodb-memory-server/commit/c081ece))
## [5.1.9](https://github.com/nodkz/mongodb-memory-server/compare/v5.1.8...v5.1.9) (2019-07-24)

@@ -8,0 +19,0 @@

18

lib/MongoMemoryReplSet.d.ts

@@ -20,11 +20,11 @@ /// <reference types="node" />

export interface ReplSetOpts {
auth: boolean;
args: string[];
count: number;
auth?: boolean;
args?: string[];
count?: number;
dbName: string;
ip: string;
name: string;
oplogSize: number;
spawn: SpawnOptions;
storageEngine: StorageEngineT;
ip?: string;
name?: string;
oplogSize?: number;
spawn?: SpawnOptions;
storageEngine?: StorageEngineT;
configSettings?: MongoMemoryReplSetConfigSettingsT;

@@ -82,4 +82,4 @@ }

_startServer(instanceOpts: MongoMemoryInstancePropT): MongoMemoryServer;
_waitForPrimary(timeout?: number): Promise<boolean>;
_waitForPrimary(timeout?: number): Promise<void>;
}
//# sourceMappingURL=MongoMemoryReplSet.d.ts.map

@@ -92,2 +92,4 @@ "use strict";

};
if (!_this.opts.replSet.args)
_this.opts.replSet.args = [];
_this.opts.replSet.args.push('--oplogSize', "" + _this.opts.replSet.oplogSize);

@@ -146,3 +148,3 @@ _this.debug = function () {

if (baseOpts.args)
opts.args = rsOpts.args.concat(baseOpts.args);
opts.args = (rsOpts.args || []).concat(baseOpts.args);
if (baseOpts.port)

@@ -195,3 +197,3 @@ opts.port = baseOpts.port;

return __awaiter(this, void 0, void 0, function () {
var servers, server;
var servers, cnt, server;
var _this = this;

@@ -211,3 +213,4 @@ return __generator(this, function (_a) {

});
while (servers.length < this.opts.replSet.count) {
cnt = this.opts.replSet.count || 1;
while (servers.length < cnt) {
this.debug(' starting a server due to count...');

@@ -347,30 +350,25 @@ server = this._startServer(this.getInstanceOpts({}));

return __awaiter(this, void 0, void 0, function () {
var replStatus, hasPrimary, restTimeout_1;
var _this = this;
var timeoutPromise;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.admin) {
return [2 /*return*/, false];
}
return [4 /*yield*/, this.admin.command({
serverStatus: 1,
metrics: 0,
locks: 0,
})];
timeoutPromise = new Promise(function (resolve, reject) {
var id = setTimeout(function () {
clearTimeout(id);
reject('Timed out in ' + timeout + 'ms. When waiting for primary.');
}, timeout);
});
return [4 /*yield*/, Promise.race(this.servers.map(function (server) {
var instanceInfo = server.getInstanceInfo();
if (!instanceInfo) {
throw new Error('_waitForPrimary - instanceInfo not present ');
}
return instanceInfo.instance.waitPrimaryReady();
}).concat([
timeoutPromise,
]))];
case 1:
replStatus = _a.sent();
this.debug(' replStatus:', replStatus);
hasPrimary = replStatus.repl.ismaster;
if (!hasPrimary) {
restTimeout_1 = timeout - 500;
if (restTimeout_1 <= 0) {
throw new Error("No PRIMARY elected yet. Timeout expired. Exiting...");
}
this.debug("No PRIMARY yet. Waiting... " + restTimeout_1 + "ms");
return [2 /*return*/, new Promise(function (resolve) {
return setTimeout(function () { return resolve(_this._waitForPrimary(restTimeout_1)); }, 500);
})];
}
return [2 /*return*/, true];
_a.sent();
this.debug('_waitForPrimary detected one primary instance ');
return [2 /*return*/];
}

@@ -377,0 +375,0 @@ });

@@ -27,2 +27,4 @@ /// <reference types="node" />

instanceReady: Function;
waitForPrimaryResolveFns: Function[];
isInstancePrimary: boolean;
instanceFailed: Function;

@@ -36,2 +38,3 @@ isInstanceReady: boolean;

getPid(): number | undefined;
waitPrimaryReady(): Promise<boolean>;
_launchMongod(mongoBin: string): ChildProcess;

@@ -38,0 +41,0 @@ _launchKiller(parentPid: number, childPid: number): ChildProcess;

@@ -61,2 +61,4 @@ "use strict";

this.killerProcess = null;
this.waitForPrimaryResolveFns = [];
this.isInstancePrimary = false;
if (this.opts.debug) {

@@ -195,2 +197,15 @@ if (!this.opts.instance)

};
MongoInstance.prototype.waitPrimaryReady = function () {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
if (this.isInstancePrimary) {
return [2 /*return*/, true];
}
return [2 /*return*/, new Promise(function (resolve) {
_this.waitForPrimaryResolveFns.push(resolve);
})];
});
});
};
MongoInstance.prototype._launchMongod = function (mongoBin) {

@@ -241,2 +256,3 @@ var spawnOpts = this.opts.spawn || {};

MongoInstance.prototype.stdoutHandler = function (message) {
var _this = this;
this.debug("" + message.toString());

@@ -271,2 +287,9 @@ var log = message.toString();

}
else if (/transition to primary complete; database writes are now permitted/.test(log)) {
this.isInstancePrimary = true;
this.waitForPrimaryResolveFns.forEach(function (resolveFn) {
_this.debug('Calling waitForPrimary resolve function');
resolveFn(true);
});
}
};

@@ -273,0 +296,0 @@ MongoInstance.childProcessList = [];

{
"name": "mongodb-memory-server-core",
"version": "5.1.9",
"version": "5.1.10",
"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.",

@@ -56,3 +56,3 @@ "main": "lib/index",

},
"gitHead": "f3c5964e4c4954386f7c70422ea1add4946498ef"
"gitHead": "5089ec6afc3dc48e7c5222484b2d01795a6e1c64"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc