From 867b0807a1fa502ae0fe04c41995fc7e89c3934c Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Mon, 18 Dec 2017 15:59:15 -0500 Subject: [PATCH] fix(sharded-tests): add `shardsvr` cmdline opt, wait for async fns NODE-1075 --- test/environments.js | 99 +++++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 38 deletions(-) diff --git a/test/environments.js b/test/environments.js index 00d2a4120..0536a5fd6 100644 --- a/test/environments.js +++ b/test/environments.js @@ -50,6 +50,33 @@ class ReplicaSetEnvironment extends EnvironmentBase { } } +const genMongosConfig = (port, options) => { + return Object.assign( + { + options: { + bind_ip: 'localhost', + port: port, + dbpath: `${__dirname}/../db/${port}`, + shardsvr: null + } + }, + options + ); +}; + +const genConfigServerConfig = (port, options) => { + return Object.assign( + { + options: { + bind_ip: 'localhost', + port: port, + dbpath: `${__dirname}/../db/${port}` + } + }, + options + ); +}; + class ShardedEnvironment extends EnvironmentBase { constructor() { super(); @@ -67,22 +94,8 @@ class ShardedEnvironment extends EnvironmentBase { } setup(callback) { - const genMongosConfig = (port, options) => { - return Object.assign( - { - options: { - bind_ip: 'localhost', - port: port, - dbpath: `${__dirname}/../db/${port}`, - shardsvr: null - } - }, - options - ); - }; - const shardingManager = this.manager; - const setupPromise = Promise.all([ + const shardPromise = Promise.all([ shardingManager.addShard( [genMongosConfig(31000), genMongosConfig(31001), genMongosConfig(31002, { arbiter: true })], { @@ -94,33 +107,43 @@ class ShardedEnvironment extends EnvironmentBase { { replSet: 'rs2' } - ), - shardingManager.addConfigurationServers( - [genMongosConfig(35000), genMongosConfig(35001), genMongosConfig(35002)], - { - replSet: 'rs3' - } - ), - shardingManager.addProxies( - [ + ) + ]); + + shardPromise + .then(() => + shardingManager.addConfigurationServers( + [ + genConfigServerConfig(35000), + genConfigServerConfig(35001), + genConfigServerConfig(35002) + ], { - bind_ip: 'localhost', - port: 51000, - configdb: 'localhost:35000,localhost:35001,localhost:35002' - }, + replSet: 'rs3' + } + ) + ) + .then(() => + shardingManager.addProxies( + [ + { + bind_ip: 'localhost', + port: 51000, + configdb: 'localhost:35000,localhost:35001,localhost:35002' + }, + { + bind_ip: 'localhost', + port: 51001, + configdb: 'localhost:35000,localhost:35001,localhost:35002' + } + ], { - bind_ip: 'localhost', - port: 51001, - configdb: 'localhost:35000,localhost:35001,localhost:35002' + binary: 'mongos' } - ], - { - binary: 'mongos' - } + ) ) - ]); - - setupPromise.then(() => callback()).catch(err => callback(err)); + .then(() => callback()) + .catch(err => callback(err)); } }