diff options
author | A. Jesse Jiryu Davis <jesse@mongodb.com> | 2019-01-18 16:49:49 -0500 |
---|---|---|
committer | A. Jesse Jiryu Davis <jesse@mongodb.com> | 2019-01-30 16:23:31 -0500 |
commit | d46942c358f42379d2c4596403dbec8522b1e755 (patch) | |
tree | cb1501ebd2a80f68098094da7700048e923841d6 | |
parent | 7a6d64aa652987fc6bbbc60ead1b753008847c3b (diff) | |
download | mongo-d46942c358f42379d2c4596403dbec8522b1e755.tar.gz |
SERVER-39099 Make dropConnections test robust
-rw-r--r-- | jstests/noPassthrough/drop_connections_replSet.js | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/jstests/noPassthrough/drop_connections_replSet.js b/jstests/noPassthrough/drop_connections_replSet.js index 0d96a9a65b9..c449d2d7b13 100644 --- a/jstests/noPassthrough/drop_connections_replSet.js +++ b/jstests/noPassthrough/drop_connections_replSet.js @@ -12,19 +12,48 @@ const primary = rst.getPrimary(); rst.awaitSecondaryNodes(); - const cfg = primary.getDB('local').system.replset.findOne(); const memberHost = cfg.members[2].host; + + function assertConnPoolStats(expectedAvailable, numTries) { + var available, res; + for (var i = 0; i < numTries; i++) { + res = assert.commandWorked(primary.adminCommand({connPoolStats: 1})); + available = res.hosts[memberHost].available; + if (available == expectedAvailable) { + return; + } + + sleep(100); + } + + // Fail informatively + jsTestLog("pool stats: " + tojson(res)); + assert.eq( + expectedAvailable, + available, + `wrong number of available connections to ${memberHost} after checking ${numTries} times`); + } + + // In initial steady state, the primary should have 1 connection to the secondary + assertConnPoolStats(1, 10); + + // To test the dropConnections command, first remove the secondary. This should have no effect + // on the existing connection pool, but it'll prevent the primary from reconnecting to it after + // dropConnections. Then, execute dropConnections and check that the primary has 0 connections + // to the secondary. const removedMember = cfg.members.splice(2, 1); cfg.version++; - assert.commandWorked(primary.adminCommand({replSetReconfig: cfg})); - assert.eq(1, primary.adminCommand({connPoolStats: 1}).hosts[memberHost].available); + // Reconfig did not affect the connection pool + assertConnPoolStats(1, 10); + + // Test dropConnections assert.commandWorked(primary.adminCommand({dropConnections: 1, hostAndPort: [memberHost]})); - assert.eq(0, primary.adminCommand({connPoolStats: 1}).hosts[memberHost].available); + assertConnPoolStats(0, 1); - // need to re-add removed node or test complain about the replset config + // Need to re-add removed node, or the test complains about the replset config cfg.members.push(removedMember[0]); cfg.version++; assert.commandWorked(primary.adminCommand({replSetReconfig: cfg})); |