summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Wahlin <james.wahlin@10gen.com>2016-10-17 10:51:33 -0400
committerJames Wahlin <james.wahlin@10gen.com>2016-10-17 12:52:23 -0400
commitc66e3f224205ff00ec67b63a081fc7ce980e5855 (patch)
treec94148d435d1fdd98225e14c25251b9eac6d88fc
parent40c24abaa05450c612f00209b81d63d3c6acd35b (diff)
downloadmongo-c66e3f224205ff00ec67b63a081fc7ce980e5855.tar.gz
SERVER-26435 Refactor replsettest.js to reduce size
-rw-r--r--jstests/aggregation/mongos_slaveok.js3
-rw-r--r--jstests/replsets/rslib.js93
-rw-r--r--jstests/sharding/auth.js5
-rw-r--r--jstests/sharding/authCommands.js5
-rw-r--r--jstests/sharding/auth_slaveok_routing.js7
-rw-r--r--jstests/sharding/count_slaveok.js5
-rw-r--r--jstests/sharding/explain_read_pref.js2
-rw-r--r--jstests/sharding/group_slaveok.js3
-rw-r--r--jstests/sharding/read_pref.js8
-rw-r--r--jstests/sharding/read_pref_cmd.js2
-rw-r--r--jstests/sharding/recovering_slaveok.js11
-rw-r--r--jstests/sharding/remove2.js4
-rw-r--r--jstests/sharding/rename.js4
-rw-r--r--jstests/sharding/repl_monitor_refresh.js2
-rw-r--r--jstests/sharding/replmonitor_bad_seed.js3
-rw-r--r--jstests/sharding/rs_stepdown_and_pooling.js14
-rw-r--r--jstests/sharding/sharding_multiple_ns_rs.js3
-rw-r--r--src/mongo/shell/replsettest.js103
18 files changed, 139 insertions, 138 deletions
diff --git a/jstests/aggregation/mongos_slaveok.js b/jstests/aggregation/mongos_slaveok.js
index 9ccf383335e..866e98da30c 100644
--- a/jstests/aggregation/mongos_slaveok.js
+++ b/jstests/aggregation/mongos_slaveok.js
@@ -3,6 +3,7 @@
* please refer to jstests/sharding/read_pref_cmd.js.
*/
(function() {
+ load('jstests/replsets/rslib.js');
var NODES = 2;
@@ -21,7 +22,7 @@
secNode.getDB('test').setProfilingLevel(2);
// wait for mongos to recognize that the slave is up
- ReplSetTest.awaitRSClientHosts(st.s, secNode, {ok: true});
+ awaitRSClientHosts(st.s, secNode, {ok: true});
var res = testDB.runCommand({aggregate: 'user', pipeline: [{$project: {x: 1}}]});
assert(res.ok, 'aggregate command failed: ' + tojson(res));
diff --git a/jstests/replsets/rslib.js b/jstests/replsets/rslib.js
index 3fb3711629a..daabd3d7415 100644
--- a/jstests/replsets/rslib.js
+++ b/jstests/replsets/rslib.js
@@ -9,6 +9,7 @@ var startSetIfSupportsReadMajority;
var waitUntilAllNodesCaughtUp;
var updateConfigIfNotDurable;
var reInitiateWithoutThrowingOnAbortedMember;
+var awaitRSClientHosts;
(function() {
"use strict";
@@ -255,4 +256,96 @@ var reInitiateWithoutThrowingOnAbortedMember;
}
}
};
+
+ /**
+ * Waits for the specified hosts to enter a certain state.
+ */
+ awaitRSClientHosts = function(conn, host, hostOk, rs, timeout) {
+ var hostCount = host.length;
+ if (hostCount) {
+ for (var i = 0; i < hostCount; i++) {
+ awaitRSClientHosts(conn, host[i], hostOk, rs);
+ }
+
+ return;
+ }
+
+ timeout = timeout || 5 * 60 * 1000;
+
+ if (hostOk == undefined)
+ hostOk = {ok: true};
+ if (host.host)
+ host = host.host;
+ if (rs)
+ rs = rs.name;
+
+ print("Awaiting " + host + " to be " + tojson(hostOk) + " for " + conn + " (rs: " + rs +
+ ")");
+
+ var tests = 0;
+
+ assert.soon(function() {
+ var rsClientHosts = conn.adminCommand('connPoolStats').replicaSets;
+ if (tests++ % 10 == 0) {
+ printjson(rsClientHosts);
+ }
+
+ for (var rsName in rsClientHosts) {
+ if (rs && rs != rsName)
+ continue;
+
+ for (var i = 0; i < rsClientHosts[rsName].hosts.length; i++) {
+ var clientHost = rsClientHosts[rsName].hosts[i];
+ if (clientHost.addr != host)
+ continue;
+
+ // Check that *all* host properties are set correctly
+ var propOk = true;
+ for (var prop in hostOk) {
+ // Use special comparator for tags because isMaster can return the fields in
+ // different order. The fields of the tags should be treated like a set of
+ // strings and 2 tags should be considered the same if the set is equal.
+ if (prop == 'tags') {
+ if (!clientHost.tags) {
+ propOk = false;
+ break;
+ }
+
+ for (var hostTag in hostOk.tags) {
+ if (clientHost.tags[hostTag] != hostOk.tags[hostTag]) {
+ propOk = false;
+ break;
+ }
+ }
+
+ for (var clientTag in clientHost.tags) {
+ if (clientHost.tags[clientTag] != hostOk.tags[clientTag]) {
+ propOk = false;
+ break;
+ }
+ }
+
+ continue;
+ }
+
+ if (isObject(hostOk[prop])) {
+ if (!friendlyEqual(hostOk[prop], clientHost[prop])) {
+ propOk = false;
+ break;
+ }
+ } else if (clientHost[prop] != hostOk[prop]) {
+ propOk = false;
+ break;
+ }
+ }
+
+ if (propOk) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }, 'timed out waiting for replica set client to recognize hosts', timeout);
+ };
}());
diff --git a/jstests/sharding/auth.js b/jstests/sharding/auth.js
index 44cef91233b..cb5e8ab42f3 100644
--- a/jstests/sharding/auth.js
+++ b/jstests/sharding/auth.js
@@ -2,6 +2,7 @@
// authentication is used
(function() {
'use strict';
+ load("jstests/replsets/rslib.js");
var adminUser = {db: "admin", username: "foo", password: "bar"};
@@ -160,8 +161,8 @@
print("logged in");
result = s.getDB("admin").runCommand({addShard: shardName});
- ReplSetTest.awaitRSClientHosts(s.s, d1.nodes, {ok: true});
- ReplSetTest.awaitRSClientHosts(s.s, d2.nodes, {ok: true});
+ awaitRSClientHosts(s.s, d1.nodes, {ok: true});
+ awaitRSClientHosts(s.s, d2.nodes, {ok: true});
s.getDB("test").foo.remove({});
diff --git a/jstests/sharding/authCommands.js b/jstests/sharding/authCommands.js
index 4dd36172d85..da8f0d80cab 100644
--- a/jstests/sharding/authCommands.js
+++ b/jstests/sharding/authCommands.js
@@ -3,6 +3,7 @@
*/
(function() {
'use strict';
+ load("jstests/replsets/rslib.js");
var st = new ShardingTest({
shards: 2,
@@ -28,8 +29,8 @@
// Secondaries should be up here, since we awaitReplication in the ShardingTest, but we *don't*
// wait for the mongos to explicitly detect them.
- ReplSetTest.awaitRSClientHosts(mongos, st.rs0.getSecondaries(), {ok: true, secondary: true});
- ReplSetTest.awaitRSClientHosts(mongos, st.rs1.getSecondaries(), {ok: true, secondary: true});
+ awaitRSClientHosts(mongos, st.rs0.getSecondaries(), {ok: true, secondary: true});
+ awaitRSClientHosts(mongos, st.rs1.getSecondaries(), {ok: true, secondary: true});
testDB.createUser({user: rwUser, pwd: password, roles: jsTest.basicUserRoles});
testDB.createUser({user: roUser, pwd: password, roles: jsTest.readOnlyUserRoles});
diff --git a/jstests/sharding/auth_slaveok_routing.js b/jstests/sharding/auth_slaveok_routing.js
index 42f34955d5a..f8dfd99f403 100644
--- a/jstests/sharding/auth_slaveok_routing.js
+++ b/jstests/sharding/auth_slaveok_routing.js
@@ -11,6 +11,7 @@
*/
(function() {
'use strict';
+ load("jstests/replsets/rslib.js");
/**
* Checks if a query to the given collection will be routed to the secondary. Returns true if
@@ -56,7 +57,7 @@
* state, which will make the ReplicaSetMonitor mark them as
* ok = false and not eligible for slaveOk queries.
*/
- ReplSetTest.awaitRSClientHosts(mongos, replTest.getSecondaries(), {ok: true, secondary: true});
+ awaitRSClientHosts(mongos, replTest.getSecondaries(), {ok: true, secondary: true});
var bulk = coll.initializeUnorderedBulkOp();
for (var x = 0; x < 20; x++) {
@@ -87,12 +88,12 @@
* A node that is previously labeled as secondary can now be a primary, so we
* wait for the replSetMonitorWatcher thread to refresh the nodes information.
*/
- ReplSetTest.awaitRSClientHosts(mongos, replTest.getSecondaries(), {ok: true, secondary: true});
+ awaitRSClientHosts(mongos, replTest.getSecondaries(), {ok: true, secondary: true});
//
// We also need to wait for the primary, it's possible that the mongos may think a node is a
// secondary but it actually changed to a primary before we send our final query.
//
- ReplSetTest.awaitRSClientHosts(mongos, replTest.getPrimary(), {ok: true, ismaster: true});
+ awaitRSClientHosts(mongos, replTest.getPrimary(), {ok: true, ismaster: true});
// Recheck if we can still query secondaries after refreshing connections.
jsTest.log('Final query to SEC');
diff --git a/jstests/sharding/count_slaveok.js b/jstests/sharding/count_slaveok.js
index 70f0d7091d9..9db720ac39e 100644
--- a/jstests/sharding/count_slaveok.js
+++ b/jstests/sharding/count_slaveok.js
@@ -2,6 +2,7 @@
// secondary is up.
(function() {
'use strict';
+ load("jstests/replsets/rslib.js");
var st = new ShardingTest(
{name: "countSlaveOk", shards: 1, mongos: 1, other: {rs: true, rs0: {nodes: 2}}});
@@ -38,10 +39,10 @@
printjson(rst.status());
// Wait for the mongos to recognize the slave
- ReplSetTest.awaitRSClientHosts(conn, sec, {ok: true, secondary: true});
+ awaitRSClientHosts(conn, sec, {ok: true, secondary: true});
// Make sure that mongos realizes that primary is already down
- ReplSetTest.awaitRSClientHosts(conn, primary, {ok: false});
+ awaitRSClientHosts(conn, primary, {ok: false});
// Need to check slaveOk=true first, since slaveOk=false will destroy conn in pool when
// master is down
diff --git a/jstests/sharding/explain_read_pref.js b/jstests/sharding/explain_read_pref.js
index 8ac4fc4ff49..c4131a9b6f4 100644
--- a/jstests/sharding/explain_read_pref.js
+++ b/jstests/sharding/explain_read_pref.js
@@ -96,7 +96,7 @@ var testAllModes = function(conn, isMongos) {
var st = new ShardingTest({shards: {rs0: {nodes: 2}}});
st.stopBalancer();
-ReplSetTest.awaitRSClientHosts(st.s, st.rs0.nodes);
+awaitRSClientHosts(st.s, st.rs0.nodes);
// Tag primary with { dc: 'ny', tag: 'one' }, secondary with { dc: 'ny', tag: 'two' }
var primary = st.rs0.getPrimary();
diff --git a/jstests/sharding/group_slaveok.js b/jstests/sharding/group_slaveok.js
index 2a18cd7a22e..68cbcdf60bd 100644
--- a/jstests/sharding/group_slaveok.js
+++ b/jstests/sharding/group_slaveok.js
@@ -1,6 +1,7 @@
// Tests group using slaveOk
(function() {
'use strict';
+ load("jstests/replsets/rslib.js");
var st = new ShardingTest(
{name: "groupSlaveOk", shards: 1, mongos: 1, other: {rs: true, rs0: {nodes: 2}}});
@@ -31,7 +32,7 @@
printjson(rst.status());
// Wait for the mongos to recognize the slave
- ReplSetTest.awaitRSClientHosts(conn, sec, {ok: true, secondary: true});
+ awaitRSClientHosts(conn, sec, {ok: true, secondary: true});
// Need to check slaveOk=true first, since slaveOk=false will destroy conn in pool when
// master is down
diff --git a/jstests/sharding/read_pref.js b/jstests/sharding/read_pref.js
index 743820e02db..1faeffa3a44 100644
--- a/jstests/sharding/read_pref.js
+++ b/jstests/sharding/read_pref.js
@@ -3,6 +3,8 @@
* can be found in dbtests/replica_set_monitor_test.cpp.
*/
+load("jstests/replsets/rslib.js");
+
var PRI_TAG = {dc: 'ny'};
var SEC_TAGS = [{dc: 'sf', s: "1"}, {dc: 'ma', s: "2"}, {dc: 'eu', s: "3"}, {dc: 'jp', s: "4"}];
var NODES = SEC_TAGS.length + 1;
@@ -72,7 +74,7 @@ var doTest = function(useDollarQuerySyntax) {
var replConfig = replTest.getReplSetConfigFromNode();
replConfig.members.forEach(function(node) {
var nodeConn = new Mongo(node.host);
- ReplSetTest.awaitRSClientHosts(conn, nodeConn, {ok: true, tags: node.tags}, replTest);
+ awaitRSClientHosts(conn, nodeConn, {ok: true, tags: node.tags}, replTest);
});
replTest.awaitReplication();
@@ -172,11 +174,11 @@ var doTest = function(useDollarQuerySyntax) {
}
// Wait for ReplicaSetMonitor to realize nodes are down
- ReplSetTest.awaitRSClientHosts(conn, stoppedNodes, {ok: false}, replTest.name);
+ awaitRSClientHosts(conn, stoppedNodes, {ok: false}, replTest.name);
// Wait for the last node to be in steady state -> secondary (not recovering)
var lastNode = replTest.nodes[NODES - 1];
- ReplSetTest.awaitRSClientHosts(conn, lastNode, {ok: true, secondary: true}, replTest.name);
+ awaitRSClientHosts(conn, lastNode, {ok: true, secondary: true}, replTest.name);
jsTest.log('connpool: ' + tojson(conn.getDB('admin').runCommand({connPoolStats: 1})));
diff --git a/jstests/sharding/read_pref_cmd.js b/jstests/sharding/read_pref_cmd.js
index 79416100fbb..b9f275ea962 100644
--- a/jstests/sharding/read_pref_cmd.js
+++ b/jstests/sharding/read_pref_cmd.js
@@ -270,7 +270,7 @@ var testAllModes = function(conn, hostList, isMongos) {
var st = new ShardingTest({shards: {rs0: {nodes: NODE_COUNT}}});
st.stopBalancer();
-ReplSetTest.awaitRSClientHosts(st.s, st.rs0.nodes);
+awaitRSClientHosts(st.s, st.rs0.nodes);
// Tag primary with { dc: 'ny', tag: 'one' }, secondary with { dc: 'ny', tag: 'two' }
var primary = st.rs0.getPrimary();
diff --git a/jstests/sharding/recovering_slaveok.js b/jstests/sharding/recovering_slaveok.js
index cd66a1b81f5..e77624fada8 100644
--- a/jstests/sharding/recovering_slaveok.js
+++ b/jstests/sharding/recovering_slaveok.js
@@ -3,6 +3,7 @@
(function() {
'use strict';
+ load("jstests/replsets/rslib.js");
var shardTest =
new ShardingTest({name: "recovering_slaveok", shards: 2, mongos: 2, other: {rs: true}});
@@ -91,15 +92,13 @@
// We need to make sure our nodes are considered accessible from mongos - otherwise we fail
// See SERVER-7274
- ReplSetTest.awaitRSClientHosts(coll.getMongo(), rsA.nodes, {ok: true});
- ReplSetTest.awaitRSClientHosts(coll.getMongo(), rsB.nodes, {ok: true});
+ awaitRSClientHosts(coll.getMongo(), rsA.nodes, {ok: true});
+ awaitRSClientHosts(coll.getMongo(), rsB.nodes, {ok: true});
// We need to make sure at least one secondary is accessible from mongos - otherwise we fail
// See SERVER-7699
- ReplSetTest.awaitRSClientHosts(
- collSOk.getMongo(), [rsA.getSecondaries()[0]], {secondary: true, ok: true});
- ReplSetTest.awaitRSClientHosts(
- collSOk.getMongo(), [rsB.getSecondaries()[0]], {secondary: true, ok: true});
+ awaitRSClientHosts(collSOk.getMongo(), [rsA.getSecondaries()[0]], {secondary: true, ok: true});
+ awaitRSClientHosts(collSOk.getMongo(), [rsB.getSecondaries()[0]], {secondary: true, ok: true});
print("SlaveOK Query...");
var sOKCount = collSOk.find().itcount();
diff --git a/jstests/sharding/remove2.js b/jstests/sharding/remove2.js
index 9d212e8fbee..888df83e4ed 100644
--- a/jstests/sharding/remove2.js
+++ b/jstests/sharding/remove2.js
@@ -1,5 +1,7 @@
// Test that removing and re-adding shard works correctly.
+load("jstests/replsets/rslib.js");
+
seedString = function(replTest) {
members = replTest.getReplSetConfig().members.map(function(elem) {
return elem.host;
@@ -32,7 +34,7 @@ addShard = function(st, replTest) {
// transport error on first attempt is expected. Make sure second attempt goes through
assert.eq(true, st.adminCommand({addshard: seed}));
}
- ReplSetTest.awaitRSClientHosts(
+ awaitRSClientHosts(
new Mongo(st.s.host), replTest.getSecondaries(), {ok: true, secondary: true});
assert.soon(function() {
diff --git a/jstests/sharding/rename.js b/jstests/sharding/rename.js
index e662b3f465d..e0518c8607e 100644
--- a/jstests/sharding/rename.js
+++ b/jstests/sharding/rename.js
@@ -1,6 +1,7 @@
(function() {
'use strict';
+ load("jstests/replsets/rslib.js");
var s = new ShardingTest({name: "rename", shards: 2, mongos: 1, rs: {oplogSize: 10}});
@@ -62,8 +63,7 @@
replTest.stop(0);
replTest.awaitSecondaryNodes();
- ReplSetTest.awaitRSClientHosts(
- s.s, replTest.getPrimary(), {ok: true, ismaster: true}, replTest.name);
+ awaitRSClientHosts(s.s, replTest.getPrimary(), {ok: true, ismaster: true}, replTest.name);
assert.writeOK(db.foo.insert({_id: 4}));
assert.commandWorked(db.foo.renameCollection('bar', true));
diff --git a/jstests/sharding/repl_monitor_refresh.js b/jstests/sharding/repl_monitor_refresh.js
index 6098c3b96ff..1e437c3ff0d 100644
--- a/jstests/sharding/repl_monitor_refresh.js
+++ b/jstests/sharding/repl_monitor_refresh.js
@@ -39,7 +39,7 @@ load("jstests/replsets/rslib.js");
reconfig(replTest, confDoc);
- ReplSetTest.awaitRSClientHosts(mongos, {host: targetHostName}, {ok: true, ismaster: true});
+ awaitRSClientHosts(mongos, {host: targetHostName}, {ok: true, ismaster: true});
// Remove first node from set
confDoc.members.shift();
diff --git a/jstests/sharding/replmonitor_bad_seed.js b/jstests/sharding/replmonitor_bad_seed.js
index d3fe61a1275..e619af509e1 100644
--- a/jstests/sharding/replmonitor_bad_seed.js
+++ b/jstests/sharding/replmonitor_bad_seed.js
@@ -14,6 +14,7 @@
*/
(function() {
'use strict';
+ load("jstests/replsets/rslib.js");
var st = new ShardingTest({shards: 1, rs: {oplogSize: 10}});
var replTest = st.rs0;
@@ -33,7 +34,7 @@
replTest.awaitSecondaryNodes();
// Verify that the replSetMonitor can reach the restarted set
- ReplSetTest.awaitRSClientHosts(st.s0, replTest.nodes, {ok: true});
+ awaitRSClientHosts(st.s0, replTest.nodes, {ok: true});
assert.writeOK(st.s0.getDB('test').user.insert({x: 1}));
diff --git a/jstests/sharding/rs_stepdown_and_pooling.js b/jstests/sharding/rs_stepdown_and_pooling.js
index 928bd515635..0e34f19636e 100644
--- a/jstests/sharding/rs_stepdown_and_pooling.js
+++ b/jstests/sharding/rs_stepdown_and_pooling.js
@@ -3,6 +3,7 @@
//
(function() {
"use strict";
+ load("jstests/replsets/rslib.js");
var st = new ShardingTest({shards: {rs0: {nodes: 2}}, mongos: 1});
@@ -68,12 +69,11 @@
jsTest.log("Waiting for mongos to acknowledge stepdown...");
- ReplSetTest.awaitRSClientHosts(
- mongos,
- secondary,
- {ismaster: true},
- st.rs0,
- 2 * 60 * 1000); // slow hosts can take longer to recognize sd
+ awaitRSClientHosts(mongos,
+ secondary,
+ {ismaster: true},
+ st.rs0,
+ 2 * 60 * 1000); // slow hosts can take longer to recognize sd
jsTest.log("Stepping back up...");
@@ -81,7 +81,7 @@
jsTest.log("Waiting for mongos to acknowledge step up...");
- ReplSetTest.awaitRSClientHosts(mongos, primary, {ismaster: true}, st.rs0, 2 * 60 * 1000);
+ awaitRSClientHosts(mongos, primary, {ismaster: true}, st.rs0, 2 * 60 * 1000);
jsTest.log("Waiting for socket timeout time...");
diff --git a/jstests/sharding/sharding_multiple_ns_rs.js b/jstests/sharding/sharding_multiple_ns_rs.js
index f3465e3b10d..183d6c24878 100644
--- a/jstests/sharding/sharding_multiple_ns_rs.js
+++ b/jstests/sharding/sharding_multiple_ns_rs.js
@@ -1,4 +1,5 @@
(function() {
+ load("jstests/replsets/rslib.js");
var s = new ShardingTest(
{name: "Sharding multiple ns", shards: 1, mongos: 1, other: {rs: true, chunkSize: 1}});
@@ -35,7 +36,7 @@
var primary = s._rs[0].test.getPrimary();
// Wait for the mongos to recognize the new primary...
- ReplSetTest.awaitRSClientHosts(db.getMongo(), primary, {ismaster: true});
+ awaitRSClientHosts(db.getMongo(), primary, {ismaster: true});
assert.eq(5, db.foo.findOne({_id: 5}).x);
assert.eq(5, db.bar.findOne({_id: 5}).x);
diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js
index eef99ae5f65..30e6a4cc850 100644
--- a/src/mongo/shell/replsettest.js
+++ b/src/mongo/shell/replsettest.js
@@ -285,18 +285,6 @@ var ReplSetTest = function(opts) {
}
/**
- * Returns the last committed OpTime for the replicaset as known by the host.
- * This function may return an OpTime with Timestamp(0,0) and Term(0) if there is no
- * last committed OpTime.
- */
- function _getLastCommittedOpTime(conn) {
- var replSetStatus =
- assert.commandWorked(conn.getDB("admin").runCommand({replSetGetStatus: 1}));
- return (replSetStatus.OpTimes || replSetStatus.optimes).lastCommittedOpTime ||
- {ts: Timestamp(0, 0), t: NumberLong(0)};
- }
-
- /**
* Returns the {readConcern: majority} OpTime for the host.
* This is the OpTime of the host's "majority committed" snapshot.
* This function may return an OpTime with Timestamp(0,0) and Term(0) if read concern majority
@@ -1646,94 +1634,3 @@ ReplSetTest.OpTimeType = {
LAST_APPLIED: 1,
LAST_DURABLE: 2,
};
-
-/**
- * Waits for the specified hosts to enter a certain state.
- */
-ReplSetTest.awaitRSClientHosts = function(conn, host, hostOk, rs, timeout) {
- var hostCount = host.length;
- if (hostCount) {
- for (var i = 0; i < hostCount; i++) {
- ReplSetTest.awaitRSClientHosts(conn, host[i], hostOk, rs);
- }
-
- return;
- }
-
- timeout = timeout || 5 * 60 * 1000;
-
- if (hostOk == undefined)
- hostOk = {ok: true};
- if (host.host)
- host = host.host;
- if (rs)
- rs = rs.name;
-
- print("Awaiting " + host + " to be " + tojson(hostOk) + " for " + conn + " (rs: " + rs + ")");
-
- var tests = 0;
-
- assert.soon(function() {
- var rsClientHosts = conn.adminCommand('connPoolStats').replicaSets;
- if (tests++ % 10 == 0) {
- printjson(rsClientHosts);
- }
-
- for (var rsName in rsClientHosts) {
- if (rs && rs != rsName)
- continue;
-
- for (var i = 0; i < rsClientHosts[rsName].hosts.length; i++) {
- var clientHost = rsClientHosts[rsName].hosts[i];
- if (clientHost.addr != host)
- continue;
-
- // Check that *all* host properties are set correctly
- var propOk = true;
- for (var prop in hostOk) {
- // Use special comparator for tags because isMaster can return the fields in
- // different order. The fields of the tags should be treated like a set of
- // strings and 2 tags should be considered the same if the set is equal.
- if (prop == 'tags') {
- if (!clientHost.tags) {
- propOk = false;
- break;
- }
-
- for (var hostTag in hostOk.tags) {
- if (clientHost.tags[hostTag] != hostOk.tags[hostTag]) {
- propOk = false;
- break;
- }
- }
-
- for (var clientTag in clientHost.tags) {
- if (clientHost.tags[clientTag] != hostOk.tags[clientTag]) {
- propOk = false;
- break;
- }
- }
-
- continue;
- }
-
- if (isObject(hostOk[prop])) {
- if (!friendlyEqual(hostOk[prop], clientHost[prop])) {
- propOk = false;
- break;
- }
- } else if (clientHost[prop] != hostOk[prop]) {
- propOk = false;
- break;
- }
- }
-
- if (propOk) {
- return true;
- }
- }
- }
-
- return false;
- }, 'timed out waiting for replica set client to recognize hosts', timeout);
-};