diff options
author | clang-format-7.0.1 <adam.martin@10gen.com> | 2019-07-26 18:42:24 -0400 |
---|---|---|
committer | ADAM David Alan Martin <adam.martin@10gen.com> | 2019-07-26 18:42:24 -0400 |
commit | c1a45ebbb0530e3d0201321d725527f1eb83ffce (patch) | |
tree | f523079dc5ded3052eefbdcaae424b7502df5b25 /jstests/noPassthrough/predictive_connpool.js | |
parent | c9599d8610c3da0b7c3da65667aff821063cf5b9 (diff) | |
download | mongo-c1a45ebbb0530e3d0201321d725527f1eb83ffce.tar.gz |
Apply formatting per `clang-format-7.0.1`
Diffstat (limited to 'jstests/noPassthrough/predictive_connpool.js')
-rw-r--r-- | jstests/noPassthrough/predictive_connpool.js | 254 |
1 files changed, 127 insertions, 127 deletions
diff --git a/jstests/noPassthrough/predictive_connpool.js b/jstests/noPassthrough/predictive_connpool.js index c38d01601e2..d92d1ba9a2f 100644 --- a/jstests/noPassthrough/predictive_connpool.js +++ b/jstests/noPassthrough/predictive_connpool.js @@ -5,155 +5,155 @@ load("jstests/libs/parallelTester.js"); */ (function() { - "use strict"; - - const st = new ShardingTest({mongos: 1, shards: 1, rs: {nodes: 2, protocolVersion: 1}}); - const kDbName = 'test'; - const mongosClient = st.s; - const mongos = mongosClient.getDB(kDbName); - const rst = st.rs0; - const primary = rst.getPrimary(); - const secondary = rst.getSecondaries()[0]; - - const cfg = primary.getDB('local').system.replset.findOne(); - const allHosts = cfg.members.map(x => x.host); - const primaryOnly = [primary.name]; - const secondaryOnly = [secondary.name]; - - function configureReplSetFailpoint(name, modeValue) { - st.rs0.nodes.forEach(function(node) { - assert.commandWorked(node.getDB("admin").runCommand({ - configureFailPoint: name, - mode: modeValue, - data: {shouldCheckForInterrupt: true}, - })); - }); +"use strict"; + +const st = new ShardingTest({mongos: 1, shards: 1, rs: {nodes: 2, protocolVersion: 1}}); +const kDbName = 'test'; +const mongosClient = st.s; +const mongos = mongosClient.getDB(kDbName); +const rst = st.rs0; +const primary = rst.getPrimary(); +const secondary = rst.getSecondaries()[0]; + +const cfg = primary.getDB('local').system.replset.findOne(); +const allHosts = cfg.members.map(x => x.host); +const primaryOnly = [primary.name]; +const secondaryOnly = [secondary.name]; + +function configureReplSetFailpoint(name, modeValue) { + st.rs0.nodes.forEach(function(node) { + assert.commandWorked(node.getDB("admin").runCommand({ + configureFailPoint: name, + mode: modeValue, + data: {shouldCheckForInterrupt: true}, + })); + }); +} + +var threads = []; + +function launchFinds({times, readPref, shouldFail}) { + jsTestLog("Starting " + times + " connections"); + for (var i = 0; i < times; i++) { + var thread = new Thread(function(connStr, readPref, dbName, shouldFail) { + var client = new Mongo(connStr); + const ret = client.getDB(dbName).runCommand( + {find: "test", limit: 1, "$readPreference": {mode: readPref}}); + + if (shouldFail) { + assert.commandFailed(ret); + } else { + assert.commandWorked(ret); + } + }, st.s.host, readPref, kDbName, shouldFail); + thread.start(); + threads.push(thread); } - - var threads = []; - - function launchFinds({times, readPref, shouldFail}) { - jsTestLog("Starting " + times + " connections"); - for (var i = 0; i < times; i++) { - var thread = new Thread(function(connStr, readPref, dbName, shouldFail) { - var client = new Mongo(connStr); - const ret = client.getDB(dbName).runCommand( - {find: "test", limit: 1, "$readPreference": {mode: readPref}}); - - if (shouldFail) { - assert.commandFailed(ret); - } else { - assert.commandWorked(ret); - } - }, st.s.host, readPref, kDbName, shouldFail); - thread.start(); - threads.push(thread); +} + +function updateSetParameters(params) { + var cmd = Object.assign({"setParameter": 1}, params); + assert.commandWorked(mongos.adminCommand(cmd)); +} + +function dropConnections() { + assert.commandWorked(mongos.adminCommand({dropConnections: 1, hostAndPort: allHosts})); +} + +var currentCheckNum = 0; +function hasConnPoolStats(args) { + const checkNum = currentCheckNum++; + jsTestLog("Check #" + checkNum + ": " + tojson(args)); + var {ready, pending, active, hosts, isAbsent} = args; + + ready = ready ? ready : 0; + pending = pending ? pending : 0; + active = active ? active : 0; + hosts = hosts ? hosts : allHosts; + + function checkStats(res, host) { + var stats = res.hosts[host]; + if (!stats) { + jsTestLog("Connection stats for " + host + " are absent"); + return isAbsent; } - } - function updateSetParameters(params) { - var cmd = Object.assign({"setParameter": 1}, params); - assert.commandWorked(mongos.adminCommand(cmd)); + jsTestLog("Connection stats for " + host + ": " + tojson(stats)); + return stats.available == ready && stats.refreshing == pending && stats.inUse == active; } - function dropConnections() { - assert.commandWorked(mongos.adminCommand({dropConnections: 1, hostAndPort: allHosts})); + function checkAllStats() { + var res = mongos.adminCommand({connPoolStats: 1}); + return hosts.map(host => checkStats(res, host)).every(x => x); } - var currentCheckNum = 0; - function hasConnPoolStats(args) { - const checkNum = currentCheckNum++; - jsTestLog("Check #" + checkNum + ": " + tojson(args)); - var {ready, pending, active, hosts, isAbsent} = args; - - ready = ready ? ready : 0; - pending = pending ? pending : 0; - active = active ? active : 0; - hosts = hosts ? hosts : allHosts; - - function checkStats(res, host) { - var stats = res.hosts[host]; - if (!stats) { - jsTestLog("Connection stats for " + host + " are absent"); - return isAbsent; - } - - jsTestLog("Connection stats for " + host + ": " + tojson(stats)); - return stats.available == ready && stats.refreshing == pending && stats.inUse == active; - } - - function checkAllStats() { - var res = mongos.adminCommand({connPoolStats: 1}); - return hosts.map(host => checkStats(res, host)).every(x => x); - } - - assert.soon(checkAllStats, "Check #" + checkNum + " failed", 10000); + assert.soon(checkAllStats, "Check #" + checkNum + " failed", 10000); - jsTestLog("Check #" + checkNum + " successful"); - } + jsTestLog("Check #" + checkNum + " successful"); +} - function checkConnPoolStats() { - const ret = mongos.runCommand({"connPoolStats": 1}); - const poolStats = ret["pools"]["NetworkInterfaceTL-TaskExecutorPool-0"]; - jsTestLog(poolStats); - } +function checkConnPoolStats() { + const ret = mongos.runCommand({"connPoolStats": 1}); + const poolStats = ret["pools"]["NetworkInterfaceTL-TaskExecutorPool-0"]; + jsTestLog(poolStats); +} - function walkThroughBehavior({primaryFollows, secondaryFollows}) { - // Start pooling with a ping - mongos.adminCommand({multicast: {ping: 0}}); - checkConnPoolStats(); +function walkThroughBehavior({primaryFollows, secondaryFollows}) { + // Start pooling with a ping + mongos.adminCommand({multicast: {ping: 0}}); + checkConnPoolStats(); - // Block connections from finishing - configureReplSetFailpoint("waitInFindBeforeMakingBatch", "alwaysOn"); + // Block connections from finishing + configureReplSetFailpoint("waitInFindBeforeMakingBatch", "alwaysOn"); - // Launch a bunch of primary finds - launchFinds({times: 10, readPref: "primary"}); + // Launch a bunch of primary finds + launchFinds({times: 10, readPref: "primary"}); - // Confirm we follow - hasConnPoolStats({active: 10, hosts: primaryOnly}); - if (secondaryFollows) { - hasConnPoolStats({ready: 10, hosts: secondaryOnly}); - } - checkConnPoolStats(); + // Confirm we follow + hasConnPoolStats({active: 10, hosts: primaryOnly}); + if (secondaryFollows) { + hasConnPoolStats({ready: 10, hosts: secondaryOnly}); + } + checkConnPoolStats(); - // Launch a bunch of secondary finds - launchFinds({times: 20, readPref: "secondary"}); + // Launch a bunch of secondary finds + launchFinds({times: 20, readPref: "secondary"}); - // Confirm we follow - hasConnPoolStats({active: 20, hosts: secondaryOnly}); - if (primaryFollows) { - hasConnPoolStats({ready: 10, active: 10, hosts: primaryOnly}); - } - checkConnPoolStats(); + // Confirm we follow + hasConnPoolStats({active: 20, hosts: secondaryOnly}); + if (primaryFollows) { + hasConnPoolStats({ready: 10, active: 10, hosts: primaryOnly}); + } + checkConnPoolStats(); - configureReplSetFailpoint("waitInFindBeforeMakingBatch", "off"); + configureReplSetFailpoint("waitInFindBeforeMakingBatch", "off"); - dropConnections(); - } + dropConnections(); +} - assert.writeOK(mongos.test.insert({x: 1})); - assert.writeOK(mongos.test.insert({x: 2})); - assert.writeOK(mongos.test.insert({x: 3})); - st.rs0.awaitReplication(); +assert.writeOK(mongos.test.insert({x: 1})); +assert.writeOK(mongos.test.insert({x: 2})); +assert.writeOK(mongos.test.insert({x: 3})); +st.rs0.awaitReplication(); - jsTestLog("Following disabled"); - walkThroughBehavior({primaryFollows: false, secondaryFollows: false}); +jsTestLog("Following disabled"); +walkThroughBehavior({primaryFollows: false, secondaryFollows: false}); - jsTestLog("Following primary node"); - updateSetParameters({ShardingTaskExecutorPoolReplicaSetMatching: "matchPrimaryNode"}); - walkThroughBehavior({primaryFollows: false, secondaryFollows: true}); +jsTestLog("Following primary node"); +updateSetParameters({ShardingTaskExecutorPoolReplicaSetMatching: "matchPrimaryNode"}); +walkThroughBehavior({primaryFollows: false, secondaryFollows: true}); - // jsTestLog("Following busiest node"); - // updateSetParameters({ShardingTaskExecutorPoolReplicaSetMatching: "matchBusiestNode"}); - // walkThroughBehavior({primaryFollows: true, secondaryFollows: true}); +// jsTestLog("Following busiest node"); +// updateSetParameters({ShardingTaskExecutorPoolReplicaSetMatching: "matchBusiestNode"}); +// walkThroughBehavior({primaryFollows: true, secondaryFollows: true}); - jsTestLog("Reseting to disabled"); - updateSetParameters({ShardingTaskExecutorPoolReplicaSetMatching: "disabled"}); - walkThroughBehavior({primaryFollows: false, secondaryFollows: false}); +jsTestLog("Reseting to disabled"); +updateSetParameters({ShardingTaskExecutorPoolReplicaSetMatching: "disabled"}); +walkThroughBehavior({primaryFollows: false, secondaryFollows: false}); - threads.forEach(function(thread) { - thread.join(); - }); +threads.forEach(function(thread) { + thread.join(); +}); - st.stop(); +st.stop(); })(); |