summaryrefslogtreecommitdiff
path: root/jstests/replsets/maxSyncSourceLagSecs.js
diff options
context:
space:
mode:
authormatt dannenberg <matt.dannenberg@10gen.com>2014-11-14 06:27:02 -0500
committermatt dannenberg <matt.dannenberg@10gen.com>2014-11-14 06:42:27 -0500
commit7ad98f86d290ffc00849f701b93e7a0aaa0c5be9 (patch)
treec386c1c70589f5eab16db7f8f3e258bc05633a44 /jstests/replsets/maxSyncSourceLagSecs.js
parent7d108f46694302f962c0efb60106e703fb8cceff (diff)
downloadmongo-7ad98f86d290ffc00849f701b93e7a0aaa0c5be9.tar.gz
SERVER-16158 make maxSyncSourceLagSecs.js resilient against incorrect primary being elected
Diffstat (limited to 'jstests/replsets/maxSyncSourceLagSecs.js')
-rw-r--r--jstests/replsets/maxSyncSourceLagSecs.js70
1 files changed, 41 insertions, 29 deletions
diff --git a/jstests/replsets/maxSyncSourceLagSecs.js b/jstests/replsets/maxSyncSourceLagSecs.js
index 934dbf50915..cfbf575025f 100644
--- a/jstests/replsets/maxSyncSourceLagSecs.js
+++ b/jstests/replsets/maxSyncSourceLagSecs.js
@@ -1,37 +1,49 @@
// Test that setting maxSyncSourceLagSecs causes the set to change sync target
-var replTest = new ReplSetTest({ nodes: 3, oplogSize: 5,
- nodeOptions: {setParameter: "maxSyncSourceLagSecs=3"}});
-replTest.startSet();
-replTest.initiate();
+(function() {
+ "use strict";
+ var name = "maxSyncSourceLagSecs";
+ var replTest = new ReplSetTest({name: name,
+ nodes: 3,
+ oplogSize: 5,
+ nodeOptions: {setParameter: "maxSyncSourceLagSecs=3"}});
+ var nodes = replTest.nodeList();
+ replTest.startSet();
+ replTest.initiate({"_id": name,
+ "members": [
+ { "_id": 0, "host": nodes[0], priority: 3 },
+ { "_id": 1, "host": nodes[1] },
+ { "_id": 2, "host": nodes[2] }],
+ });
-var master = replTest.getMaster();
-master.getDB("foo").bar.save({a: 1});
-replTest.awaitReplication();
-var slaves = replTest.liveNodes.slaves;
+ var master = replTest.getMaster();
+ master.getDB("foo").bar.save({a: 1});
+ replTest.awaitReplication();
+ var slaves = replTest.liveNodes.slaves;
-// need to put at least maxSyncSourceLagSecs b/w first op and subsequent ops
-// so that the shouldChangeSyncSource logic goes into effect
-sleep(3000);
+ // 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");
-assert.commandWorked(slaves[1].getDB("admin").runCommand({replSetSyncFrom: slaves[0].name}));
-assert.soon(function() {
- return (replTest.status().members[2].syncingTo == slaves[0].name);
- }, "sync target not changed to other slave");
-printjson(replTest.status());
+ jsTestLog("Setting sync target of slave 2 to slave 1");
+ assert.commandWorked(slaves[1].getDB("admin").runCommand({replSetSyncFrom: slaves[0].name}));
+ assert.soon(function() {
+ return (replTest.status().members[2].syncingTo === slaves[0].name);
+ }, "sync target not changed to other slave");
+ printjson(replTest.status());
-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}));
-master.getDB("foo").bar.save({a: 2});
+ 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}));
+ master.getDB("foo").bar.save({a: 2});
-assert.soon(function() {
- return (replTest.status().members[2].syncingTo == master.name);
- }, "sync target not changed back to primary");
-printjson(replTest.status());
+ assert.soon(function() {
+ return (replTest.status().members[2].syncingTo === master.name);
+ }, "sync target not changed back to primary");
+ printjson(replTest.status());
-assert.soon(function() {
- return (slaves[1].getDB("foo").bar.count() == 2);
- }, "slave should have caught up after syncing to primary.");
+ assert.soon(function() {
+ return (slaves[1].getDB("foo").bar.count() === 2);
+ }, "slave should have caught up after syncing to primary.");
-assert.commandWorked(slaves[0].getDB("admin").$cmd.sys.unlock.findOne());
-replTest.stopSet();
+ assert.commandWorked(slaves[0].getDB("admin").$cmd.sys.unlock.findOne());
+ replTest.stopSet();
+}());