summaryrefslogtreecommitdiff
path: root/jstests/replsets
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2012-05-10 06:57:54 +0200
committerAntonin Kral <a.kral@bobek.cz>2012-05-10 06:57:54 +0200
commit61619b3142c1de8f60f91964ff2656054d4f11a6 (patch)
treed3aaf9d1e70cac8efa0856e5b5ba39e2fb9dc526 /jstests/replsets
parenteaaa7b30c99b89b5483e0a372bb73fe8c8695185 (diff)
downloadmongodb-61619b3142c1de8f60f91964ff2656054d4f11a6.tar.gz
Imported Upstream version 2.0.5
Diffstat (limited to 'jstests/replsets')
-rw-r--r--jstests/replsets/reconfig.js18
-rw-r--r--jstests/replsets/replset_remove_node.js13
-rw-r--r--jstests/replsets/replsetprio1.js75
3 files changed, 64 insertions, 42 deletions
diff --git a/jstests/replsets/reconfig.js b/jstests/replsets/reconfig.js
index 55ee505..7d43720 100644
--- a/jstests/replsets/reconfig.js
+++ b/jstests/replsets/reconfig.js
@@ -60,10 +60,18 @@ replTest.stopSet();
replTest2 = new ReplSetTest({name : 'testSet2', nodes : 1});
nodes = replTest2.startSet();
-result = nodes[0].getDB("admin").runCommand({replSetInitiate : {_id : "testSet2", members : [
- {_id : 0, tags : ["member0"]}
- ]}});
-
-assert(result.errmsg.match(/bad or missing host field/) , "error message doesn't match, got result:" + 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();
diff --git a/jstests/replsets/replset_remove_node.js b/jstests/replsets/replset_remove_node.js
index 9fef721..bf99b12 100644
--- a/jstests/replsets/replset_remove_node.js
+++ b/jstests/replsets/replset_remove_node.js
@@ -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;
diff --git a/jstests/replsets/replsetprio1.js b/jstests/replsets/replsetprio1.js
index a002476..aeeb749 100644
--- a/jstests/replsets/replsetprio1.js
+++ b/jstests/replsets/replsetprio1.js
@@ -1,4 +1,3 @@
-// FAILING TEST
// should check that election happens in priority order
doTest = function( signal ) {
@@ -7,47 +6,55 @@ doTest = function( signal ) {
var nodes = replTest.nodeList();
replTest.startSet();
- replTest.node[0].initiate({"_id" : "unicomplex",
+ replTest.initiate({"_id" : "testSet",
"members" : [
- {"_id" : 0, "host" : nodes[0], "priority" : 1},
- {"_id" : 1, "host" : nodes[1], "priority" : 2},
+ {"_id" : 0, "host" : nodes[0], "priority" : 1},
+ {"_id" : 1, "host" : nodes[1], "priority" : 2},
{"_id" : 2, "host" : nodes[2], "priority" : 3}]});
- sleep(10000);
-
- // 2 should be master
- var m3 = replTest.nodes[2].runCommand({ismaster:1})
-
- // FAILS: node[0] is elected master, regardless of priority
- assert(m3.ismaster, 'highest priority is master');
+ // 2 should be master (give this a while to happen, as 0 will be elected, then demoted)
+ assert.soon(function() {
+ var m2 = replTest.nodes[2].getDB("admin").runCommand({ismaster:1});
+ return m2.ismaster;
+ }, 'highest priority is master', 120000);
// kill 2, 1 should take over
- var m3Id = replTest.getNodeId(nodes[2]);
- replTest.stop(m3Id);
-
- sleep(10000);
-
- var m2 = replTest.nodes[1].runCommand({ismaster:1})
- assert(m2.ismaster, 'node 2 is master');
+ replTest.stop(2);
- // bring 2 back up, nothing should happen
- replTest.start(m3Id);
+ // do some writes on 1
+ master = replTest.getMaster();
+ for (i=0; i<1000; i++) {
+ master.getDB("foo").bar.insert({i:i});
+ }
sleep(10000);
- m2 = replTest.nodes[1].runCommand({ismaster:1})
- assert(m2.ismaster, 'node 2 is still master');
-
- // kill 1, 2 should become master
- var m2Id = replTest.getNodeId(nodes[1]);
- replTest.stop(m2Id);
-
- sleep(10000);
-
- m3 = replTest.nodes[2].runCommand({ismaster:1})
- assert(m3.ismaster, 'node 3 is master');
-
- replTest.stopSet( signal );
+ for (i=0; i<1000; i++) {
+ master.getDB("bar").baz.insert({i:i});
+ }
+
+ var m1 = replTest.nodes[1].getDB("admin").runCommand({ismaster:1})
+ assert(m1.ismaster, 'node 2 is master');
+
+ // bring 2 back up, 2 should wait until caught up and then become master
+ replTest.restart(2);
+ assert.soon(function() {
+ try {
+ m2 = replTest.nodes[2].getDB("admin").runCommand({ismaster:1})
+ return m2.ismaster;
+ }
+ catch (e) {
+ print(e);
+ }
+ return false;
+ }, 'node 2 is master again');
+
+ // make sure nothing was rolled back
+ master = replTest.getMaster();
+ for (i=0; i<1000; i++) {
+ assert(master.getDB("foo").bar.findOne({i:i}) != null, 'checking '+i);
+ assert(master.getDB("bar").baz.findOne({i:i}) != null, 'checking '+i);
+ }
}
-//doTest( 15 );
+doTest( 15 );