Skip to content

Commit

Permalink
SERVER-1598 rs getlasterror default test refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
banker authored and erh committed Sep 15, 2010
1 parent 5ecb7b9 commit cfeb9c9
Showing 1 changed file with 22 additions and 30 deletions.
52 changes: 22 additions & 30 deletions jstests/replsets/replset5.js
Expand Up @@ -8,7 +8,7 @@ doTest = function (signal) {
// Initiate set with default for getLastError
var config = replTest.getReplSetConfig();
config.settings = {};
config.settings.getLastErrorDefaults = { 'w': 3, 'wtimeout': 10000 };
config.settings.getLastErrorDefaults = { 'w': 3, 'wtimeout': 20000 };

replTest.initiate(config);

Expand All @@ -18,59 +18,51 @@ doTest = function (signal) {
var testDB = "foo";

// Initial replication
master.getDB(testDB).bar.save({ a: 1 });
master.getDB("barDB").bar.save({ a: 1 });
replTest.awaitReplication();

var slaves = replTest.liveNodes.slaves;

// These writes should be replicated immediately
master.getDB(testDB).foo.insert({ n: 1 });
master.getDB(testDB).foo.insert({ n: 2 });
master.getDB(testDB).foo.insert({ n: 3 });

// *** NOTE ***: The slaves have the data when I run this:
master.getDB("admin").runCommand({ getlasterror: 1, w: 3, wtimeout: 5000 });

// But when I run the test with no defaults, they don't:
// master.getDB("admin").runCommand({getlasterror: 1});
// *** NOTE ***: The default doesn't seem to be propogating.
// When I run getlasterror with no defaults, the slaves don't have the data:
// These getlasterror commands can be run individually to verify this.
//master.getDB("admin").runCommand({ getlasterror: 1, w: 3, wtimeout: 20000 });
master.getDB("admin").runCommand({getlasterror: 1});

var slaves = replTest.liveNodes.slaves;
slaves[0].setSlaveOk();
slaves[1].setSlaveOk();

print("Testing slave I");
print("Testing slave counts");

// These should all have 3 documents, but they don't always.
var master1count = master.getDB(testDB).foo.count();
assert( master1count == 3, "Master has " + master1count + " of 3 documents!");

var slave0count = slaves[0].getDB(testDB).foo.count();
assert( slave0count == 3, "Slave 0 has " + slave0count + " of 3 documents!");

var slave1count = slaves[1].getDB(testDB).foo.count();
assert( slave1count == 3, "Slave 1 has " + slave1count + " of 3 documents!");

print("Testing slave 0");

var s0 = slaves[0].getDB(testDB).foo.find();
assert(s0.next()['n']);
assert(s0.next()['n']);
assert(s0.next()['n']);

print("Testing slave II");
print("Testing slave 1");

var s1 = slaves[1].getDB(testDB).foo.find();
assert(s1.next()['n']);
assert(s1.next()['n']);
assert(s1.next()['n']);

// Let's re-initialize the replica set with a new getlasterror
var config = replTest.getReplSetConfig();
var c = master.getDB("local")['system.replset'].findOne();
printjson(c);
config.settings = {};
config.settings.getLastErrorDefaults = { 'w': 5, 'wtimeout': 1000000 };
config.version = c.version + 1;

print("Reinitiating");
replTest.initiate(config, 'replSetReconfig');

var master = replTest.getMaster();

master.getDB(testDB).baz.insert({ n: 3 });

// *** NOTE ***: This should never return given the timeout set above, but it returns right away.
print("NOTE");
master.getDB(testDB).runCommand({ getlasterror: 1, w: 5, wtimeout: 5000000 });
print("NOTE2");

// End test
replTest.stopSet(signal);
}
Expand Down

0 comments on commit cfeb9c9

Please sign in to comment.