0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

Fix flaky tests and add more debugging

This commit is contained in:
Kristina 2012-02-13 15:38:04 -05:00
parent 5f3e16f58d
commit 86f8966f2c
3 changed files with 54 additions and 43 deletions

View File

@ -68,20 +68,18 @@ replTest.stopSet();
replTest2 = new ReplSetTest({name : 'testSet2', nodes : 1});
nodes = replTest2.startSet();
var initiate = function() {
return nodes[0].getDB("admin").runCommand({replSetInitiate : {_id : "testSet2", members : [
{_id : 0, tags : ["member0"]}
]}});
};
result = initiate();
// if the test machine is slow, it might not have reached emptyconfig state, yet
if ("startupStatus" in result && result.startupStatus == 1) {
sleep(10000);
result = initiate();
}
assert( result.errmsg.match(/bad or missing host field/) , tojson(result) );
assert.soon(function() {
try {
result = nodes[0].getDB("admin").runCommand({replSetInitiate : {_id : "testSet2", members : [
{_id : 0, tags : ["member0"]}
]}});
printjson(result);
return result.errmsg.match(/bad or missing host field/);
}
catch (e) {
print(e);
}
return false;
});
replTest2.stopSet();

View File

@ -1,6 +1,6 @@
doTest = function( signal ) {
// Make sure that we can manually shutdown a remove a
// Make sure that we can manually shutdown a remove a
// slave from the configuration.
// Create a new replica set test. Specify set name and the number of nodes you want.
@ -12,7 +12,14 @@ doTest = function( signal ) {
// Call initiate() to send the replSetInitiate command
// This will wait for initiation
replTest.initiate();
var name = replTest.nodeList();
replTest.initiate({"_id" : "testSet",
"members" : [
// make sure 0 becomes primary so we don't try to remove the
// primary below
{"_id" : 0, "host" : name[0], priority:2},
{"_id" : 1, "host" : name[1]},
{"_id" : 2, "host" : name[2]}]});
// Call getMaster to return a reference to the node that's been
// elected master.
@ -41,7 +48,7 @@ doTest = function( signal ) {
print(e);
}
// Make sure that a new master comes up
master = replTest.getMaster();
slaves = replTest.liveNodes.slaves;

View File

@ -20,8 +20,8 @@ replTest.initiate({_id : name, members :
],
settings : {
getLastErrorModes : {
"important" : {"dc" : 2, "server" : 3},
"a machine" : {"server" : 1}
"2 dc and 3 server" : {"dc" : 2, "server" : 3},
"1 and 2" : {"server" : 1}
}
}});
@ -32,17 +32,17 @@ var config = master.getDB("local").system.replset.findOne();
printjson(config);
var modes = config.settings.getLastErrorModes;
assert.eq(typeof modes, "object");
assert.eq(modes.important.dc, 2);
assert.eq(modes.important.server, 3);
assert.eq(modes["a machine"]["server"], 1);
assert.eq(modes["2 dc and 3 server"].dc, 2);
assert.eq(modes["2 dc and 3 server"].server, 3);
assert.eq(modes["1 and 2"]["server"], 1);
config.version++;
config.members[1].priority = 1.5;
config.members[2].priority = 2;
modes.rack = {"sf" : 1};
modes.niceRack = {"sf" : 2};
modes["a machine"]["2"] = 1;
modes.on2 = {"2" : 1}
modes["3 or 4"] = {"sf" : 1};
modes["3 and 4"] = {"sf" : 2};
modes["1 and 2"]["2"] = 1;
modes["2"] = {"2" : 1}
try {
master.getDB("admin").runCommand({replSetReconfig : config});
@ -60,11 +60,11 @@ printjson(config);
modes = config.settings.getLastErrorModes;
assert.eq(typeof modes, "object");
assert.eq(modes.important.dc, 2);
assert.eq(modes.important.server, 3);
assert.eq(modes["a machine"]["server"], 1);
assert.eq(modes.rack["sf"], 1);
assert.eq(modes.niceRack["sf"], 2);
assert.eq(modes["2 dc and 3 server"].dc, 2);
assert.eq(modes["2 dc and 3 server"].server, 3);
assert.eq(modes["1 and 2"]["server"], 1);
assert.eq(modes["3 or 4"]["sf"], 1);
assert.eq(modes["3 and 4"]["sf"], 2);
myprint("bridging");
replTest.bridge();
@ -84,6 +84,7 @@ myprint("bridge 7");
replTest.partition(3, 4);
myprint("done bridging");
myprint("paritions: [0-1-2-0] [3] [4]")
myprint("test1");
myprint("2 should be primary");
master = replTest.getMaster();
@ -93,27 +94,32 @@ printjson(master.getDB("admin").runCommand({replSetGetStatus:1}));
var timeout = 20000;
master.getDB("foo").bar.insert({x:1});
var result = master.getDB("foo").runCommand({getLastError:1,w:"rack",wtimeout:timeout});
var result = master.getDB("foo").runCommand({getLastError:1,w:"3 or 4",wtimeout:timeout});
printjson(result);
assert.eq(result.err, "timeout");
replTest.unPartition(1,4);
myprint("partitions: [1-4] [0-1-2-0] [3]");
myprint("test2");
master.getDB("foo").bar.insert({x:1});
result = master.getDB("foo").runCommand({getLastError:1,w:"rack",wtimeout:timeout});
result = master.getDB("foo").runCommand({getLastError:1,w:"3 or 4",wtimeout:timeout});
printjson(result);
assert.eq(result.err, null);
myprint("partitions: [1-4] [0-1-2-0] [3]");
myprint("test3");
result = master.getDB("foo").runCommand({getLastError:1,w:"niceRack",wtimeout:timeout});
result = master.getDB("foo").runCommand({getLastError:1,w:"3 and 4",wtimeout:timeout});
printjson(result);
assert.eq(result.err, "timeout");
replTest.unPartition(3,4);
myprint("partitions: [0-4-3] [0-1-2-0]");
myprint("31004 should sync from 31001 (31026)");
myprint("31003 should sync from 31004 (31024)");
myprint("test4");
result = master.getDB("foo").runCommand({getLastError:1,w:"niceRack",wtimeout:timeout});
result = master.getDB("foo").runCommand({getLastError:1,w:"3 and 4",wtimeout:timeout});
printjson(result);
assert.eq(result.err, null);
@ -123,21 +129,21 @@ printjson(result);
assert.eq(result.code, 14830);
assert.eq(result.ok, 0);
myprint("test on2");
myprint("test mode 2");
master.getDB("foo").bar.insert({x:1});
result = master.getDB("foo").runCommand({getLastError:1,w:"on2",wtimeout:0});
result = master.getDB("foo").runCommand({getLastError:1,w:"2",wtimeout:0});
printjson(result);
assert.eq(result.err, null);
myprint("test two on the primary");
master.getDB("foo").bar.insert({x:1});
result = master.getDB("foo").runCommand({getLastError:1,w:"a machine",wtimeout:0});
result = master.getDB("foo").runCommand({getLastError:1,w:"1 and 2",wtimeout:0});
printjson(result);
assert.eq(result.err, null);
myprint("test5");
master.getDB("foo").bar.insert({x:1});
result = master.getDB("foo").runCommand({getLastError:1,w:"important",wtimeout:timeout});
result = master.getDB("foo").runCommand({getLastError:1,w:"2 dc and 3 server",wtimeout:timeout});
printjson(result);
assert.eq(result.err, null);
@ -152,13 +158,13 @@ master = replTest.getMaster();
myprint("test6");
master.getDB("foo").bar.insert({x:1});
result = master.getDB("foo").runCommand({getLastError:1,w:"niceRack",wtimeout:timeout});
result = master.getDB("foo").runCommand({getLastError:1,w:"3 and 4",wtimeout:timeout});
printjson(result);
assert.eq(result.err, null);
myprint("test on2");
myprint("test mode 2");
master.getDB("foo").bar.insert({x:1});
result = master.getDB("foo").runCommand({getLastError:1,w:"on2",wtimeout:timeout});
result = master.getDB("foo").runCommand({getLastError:1,w:"2",wtimeout:timeout});
printjson(result);
assert.eq(result.err, "timeout");