summaryrefslogtreecommitdiff
path: root/jstests/replsets/replsetarb2.js
diff options
context:
space:
mode:
authorKyle Banker <kylebanker@gmail.com>2010-07-30 14:02:27 -0400
committerKyle Banker <kylebanker@gmail.com>2010-07-30 14:02:37 -0400
commit2c9fbfbcd6eb101303681891efd5bd6826f72c36 (patch)
treeb6627f0962c379458dbe62acbb55985ea32e1ea0 /jstests/replsets/replsetarb2.js
parentb5611894f0d8dd6730df65dce8dbd746f04d8e79 (diff)
downloadmongo-2c9fbfbcd6eb101303681891efd5bd6826f72c36.tar.gz
SERVER-1463 test failover with arbiter
Diffstat (limited to 'jstests/replsets/replsetarb2.js')
-rw-r--r--jstests/replsets/replsetarb2.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/jstests/replsets/replsetarb2.js b/jstests/replsets/replsetarb2.js
new file mode 100644
index 00000000000..0dd8a3ded31
--- /dev/null
+++ b/jstests/replsets/replsetarb2.js
@@ -0,0 +1,45 @@
+// Election when master fails and remaining nodes are an arbiter and a slave.
+// Note that in this scenario, the arbiter needs two votes.
+
+doTest = function( signal ) {
+
+ var replTest = new ReplSetTest( {name: 'unicomplex', nodes: 3} );
+ var nodes = replTest.nodeList();
+
+ print(tojson(nodes));
+
+ var conns = replTest.startSet();
+ var r = replTest.initiate({"_id" : "unicomplex",
+ "members" : [
+ {"_id" : 0, "host" : nodes[0] },
+ {"_id" : 1, "host" : nodes[1], "arbiterOnly" : true, "votes": 2},
+ {"_id" : 2, "host" : nodes[2] }]});
+
+ // Make sure we have a master
+ var master = replTest.getMaster();
+
+ // Make sure we have an arbiter
+ assert.soon(function() {
+ res = conns[1].getDB("admin").runCommand({replSetGetStatus: 1});
+ printjson(res);
+ return res.myState == 7;
+ }, "Aribiter failed to initialize.");
+
+ // Wait for initial replication
+ master.getDB("foo").foo.insert({a: "foo"});
+ replTest.awaitReplication();
+
+ // Now kill the original master
+ mId = replTest.getNodeId( master );
+ replTest.stop( mId );
+
+ // And make sure that the slave is promoted
+ new_master = replTest.getMaster();
+
+ newMasterId = replTest.getNodeId( new_master );
+ assert( newMasterId == 2, "Slave wasn't promoted to new master");
+
+ replTest.stopSet( signal );
+}
+
+doTest( 15 );