diff options
Diffstat (limited to 'jstests/replsets')
-rw-r--r-- | jstests/replsets/rslib.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/jstests/replsets/rslib.js b/jstests/replsets/rslib.js index bff0a04182d..6635c4be14b 100644 --- a/jstests/replsets/rslib.js +++ b/jstests/replsets/rslib.js @@ -1,4 +1,6 @@ var wait, occasionally, reconnect, getLatestOp, waitForAllMembers, reconfig, awaitOpTime; +var waitUntilAllNodesCaughtUp; + (function () { "use strict"; var count = 0; @@ -148,4 +150,35 @@ awaitOpTime = function (node, opTime) { }); }; +/** + * Uses the results of running replSetGetStatus against an arbitrary replset node to wait until + * all nodes in the set are replicated through the same optime. + */ +waitUntilAllNodesCaughtUp = function(rs) { + var rsStatus; + var firstConflictingIndex; + var ot; + var otherOt; + assert.soon(function () { + rsStatus = rs[0].adminCommand('replSetGetStatus'); + if (rsStatus.ok != 1) { + return false; + } + assert.eq(rs.length, rsStatus.members.length, tojson(rsStatus)); + ot = rsStatus.members[0].optime; + for (var i = 1; i < rsStatus.members.length; ++i) { + otherOt = rsStatus.members[i].optime; + if (bsonWoCompare({ts: otherOt.ts}, {ts: ot.ts}) || + bsonWoCompare({t: otherOt.t}, {t: ot.t})) { + firstConflictingIndex = i; + return false; + } + } + return true; + }, function () { + return "Optimes of members 0 (" + tojson(ot) + ") and " + firstConflictingIndex + " (" + + tojson(otherOt) + ") are different in " + tojson(rsStatus); + }); +}; + }()); |