summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorMatt Dannenberg <matt.dannenberg@10gen.com>2014-02-03 14:49:03 -0500
committerDan Pasette <dan@mongodb.com>2014-03-15 15:21:28 -0400
commitd4ef06166f8249d9b4f97c621b4a0336f8f1c828 (patch)
tree7b10cc1d8a0df2bb00b841c22ef38fd75dbeba4c /jstests
parent317cb98a19baa2e9731c735ee223a746b60bb334 (diff)
downloadmongo-d4ef06166f8249d9b4f97c621b4a0336f8f1c828.tar.gz
update and repair replsets.slavedelay1.js
Diffstat (limited to 'jstests')
-rw-r--r--jstests/replsets/slavedelay1.js61
1 files changed, 20 insertions, 41 deletions
diff --git a/jstests/replsets/slavedelay1.js b/jstests/replsets/slavedelay1.js
index 13c6adfcdf3..623fa8a5ab4 100644
--- a/jstests/replsets/slavedelay1.js
+++ b/jstests/replsets/slavedelay1.js
@@ -12,17 +12,16 @@ doTest = function( signal ) {
/* set slaveDelay to 30 seconds */
var config = replTest.getReplSetConfig();
config.members[2].priority = 0;
- config.members[2].slaveDelay = 10;
+ config.members[2].slaveDelay = 30;
replTest.initiate(config);
var master = replTest.getMaster().getDB(name);
var slaveConns = replTest.liveNodes.slaves;
- var slave = [];
+ var slaves = [];
for (var i in slaveConns) {
var d = slaveConns[i].getDB(name);
- d.getMongo().setSlaveOk();
- slave.push(d);
+ slaves.push(d);
}
waitForAllMembers(master);
@@ -35,68 +34,44 @@ doTest = function( signal ) {
assert.eq(doc.x, 1);
// make sure slave has it
- var doc = slave[0].foo.findOne();
+ var doc = slaves[0].foo.findOne();
assert.eq(doc.x, 1);
// make sure delayed slave doesn't have it
- assert.eq(slave[1].foo.findOne(), null);
-
for (var i=0; i<8; i++) {
- assert.eq(slave[1].foo.findOne(), null);
+ assert.eq(slaves[1].foo.findOne(), null);
sleep(1000);
}
- // now delayed slave should have it
+ // within 30 seconds delayed slave should have it
assert.soon(function() {
- var z = slave[1].foo.findOne();
+ var z = slaves[1].foo.findOne();
return z && z.x == 1;
});
/************* Part 2 *******************/
- // how about non-initial sync?
-
- for (var i=0; i<100; i++) {
- master.foo.insert({_id : i, "foo" : "bar"});
- }
- master.runCommand({getlasterror:1,w:2});
-
- assert.eq(master.foo.findOne({_id : 99}).foo, "bar");
- assert.eq(slave[0].foo.findOne({_id : 99}).foo, "bar");
- assert.eq(slave[1].foo.findOne({_id : 99}), null);
-
- for (var i=0; i<8; i++) {
- assert.eq(slave[1].foo.findOne({_id:99}), null);
- sleep(1000);
- }
-
- assert.soon(function() {
- var z = slave[1].foo.findOne({_id : 99});
- return z && z.foo == "bar";
- });
-
- /************* Part 3 *******************/
-
// how about if we add a new server? will it sync correctly?
-
conn = replTest.add();
config = master.getSisterDB("local").system.replset.findOne();
printjson(config);
config.version++;
- config.members.push({_id : 3, host : host+":"+replTest.ports[replTest.ports.length-1],priority:0, slaveDelay:10});
+ config.members.push({_id: 3,
+ host: host+":"+replTest.ports[replTest.ports.length-1],
+ priority:0,
+ slaveDelay:30});
master = reconfig(replTest, config);
master = master.getSisterDB(name);
- // it should be all caught up now
+ // wait for the node to catch up
+ replTest.awaitReplication();
master.foo.insert({_id : 123, "x" : "foo"});
master.runCommand({getlasterror:1,w:2});
- conn.setSlaveOk();
-
for (var i=0; i<8; i++) {
assert.eq(conn.getDB(name).foo.findOne({_id:123}), null);
sleep(1000);
@@ -107,7 +82,7 @@ doTest = function( signal ) {
return z != null && z.x == "foo"
});
- /************* Part 4 ******************/
+ /************* Part 3 ******************/
print("reconfigure slavedelay");
@@ -120,6 +95,7 @@ doTest = function( signal ) {
return conn.getDB("local").system.replset.findOne().version == config.version;
});
+ // wait for node to become secondary
assert.soon(function() {
var result = conn.getDB("admin").isMaster();
printjson(result);
@@ -130,12 +106,15 @@ doTest = function( signal ) {
master.foo.insert({_id : 124, "x" : "foo"});
assert(master.foo.findOne({_id:124}) != null);
- for (var i=0; i<13; i++) {
+ for (var i=0; i<10; i++) {
assert.eq(conn.getDB(name).foo.findOne({_id:124}), null);
sleep(1000);
}
- replTest.awaitReplication();
+ // the node should have the document in 15 seconds (20 for some safety against races)
+ assert.soon(function() {
+ return conn.getDB(name).foo.findOne({_id:124}) != null;
+ }, 10*1000);
replTest.stopSet();
}