From a04a9586894e1a64fd7514161b3c0bfd5291e5bf Mon Sep 17 00:00:00 2001 From: nodkz Date: Tue, 6 Jun 2017 22:06:25 +0600 Subject: [PATCH] fix(Concurrency): Multiple databases start ups in serial. This fix avoid parallel download of mongod binaries. --- src/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 5edb31abc..52f6e889c 100644 --- a/src/index.js +++ b/src/index.js @@ -33,6 +33,7 @@ async function generateConnectionString(port: number, dbName: ?string): Promise< } export default class MongoDBMemoryServer { + static mongodHelperStartup: ?Promise; isRunning: boolean = false; runningInstance: ?Promise; opts: MongoMemoryServerOptsT; @@ -111,9 +112,15 @@ export default class MongoDBMemoryServer { mongodCli.debug.enabled = this.opts.debug; + if (this.constructor.mongodHelperStartup) { + await this.constructor.mongodHelperStartup; + } + // Download if not exists mongo binaries in ~/.mongodb-prebuilt // After that startup MongoDB instance - await mongodCli.run(); + const startupPromise = mongodCli.run(); + this.constructor.mongodHelperStartup = startupPromise; + await startupPromise; data.mongodCli = mongodCli; data.tmpDir = tmpDir;