summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
Diffstat (limited to 'jstests')
-rw-r--r--jstests/replsets/maxSyncSourceLagSecs.js8
-rw-r--r--jstests/replsets/rslib.js12
2 files changed, 15 insertions, 5 deletions
diff --git a/jstests/replsets/maxSyncSourceLagSecs.js b/jstests/replsets/maxSyncSourceLagSecs.js
index 96d6a530aee..3e0dc7bd3b1 100644
--- a/jstests/replsets/maxSyncSourceLagSecs.js
+++ b/jstests/replsets/maxSyncSourceLagSecs.js
@@ -28,14 +28,14 @@
master.getDB("foo").bar.save({a: 1});
replTest.awaitReplication();
- // need to put at least maxSyncSourceLagSecs b/w first op and subsequent ops
- // so that the shouldChangeSyncSource logic goes into effect
- sleep(4000);
-
jsTestLog("Setting sync target of slave 2 to slave 1");
syncFrom(slaves[1], slaves[0], replTest);
printjson(replTest.status());
+ // need to put at least maxSyncSourceLagSecs b/w first op and subsequent ops
+ // so that the shouldChangeSyncSource logic goes into effect
+ sleep(4000);
+
jsTestLog("Lock slave 1 and add some docs. Force sync target for slave 2 to change to primary");
assert.commandWorked(slaves[0].getDB("admin").runCommand({fsync: 1, lock: 1}));
diff --git a/jstests/replsets/rslib.js b/jstests/replsets/rslib.js
index 93fa1393984..1471824bd8f 100644
--- a/jstests/replsets/rslib.js
+++ b/jstests/replsets/rslib.js
@@ -29,14 +29,24 @@ var getLastOpTime;
*/
syncFrom = function(syncingNode, desiredSyncSource, rst) {
jsTestLog("Forcing " + syncingNode.name + " to sync from " + desiredSyncSource.name);
- stopServerReplication(syncingNode);
+
+ // Ensure that 'desiredSyncSource' doesn't already have the dummy write sitting around from
+ // a previous syncFrom attempt.
var dummyName = "dummyForSyncFrom";
+ rst.getPrimary().getDB(dummyName).getCollection(dummyName).drop();
+ assert.soonNoExcept(function() {
+ return desiredSyncSource.getDB(dummyName).getCollection(dummyName).findOne() == null;
+ });
+
+ stopServerReplication(syncingNode);
+
assert.writeOK(rst.getPrimary().getDB(dummyName).getCollection(dummyName).insert({a: 1}));
// Wait for 'desiredSyncSource' to get the dummy write we just did so we know it's
// definitely ahead of 'syncingNode' before we call replSetSyncFrom.
assert.soonNoExcept(function() {
return desiredSyncSource.getDB(dummyName).getCollection(dummyName).findOne({a: 1});
});
+
assert.commandWorked(syncingNode.adminCommand({replSetSyncFrom: desiredSyncSource.name}));
restartServerReplication(syncingNode);
rst.awaitSyncSource(syncingNode, desiredSyncSource);