Files
mongo/jstests/replsets/replsetprio1.js

45 lines
1.5 KiB
JavaScript
Raw Normal View History

2010-07-28 10:25:31 -04:00
// should check that election happens in priority order
(function() {
"use strict";
2010-07-28 10:25:31 -04:00
var replTest = new ReplSetTest( {name: 'testSet', nodes: 3} );
var nodenames = replTest.nodeList();
2010-07-28 10:25:31 -04:00
var nodes = replTest.startSet();
replTest.initiate({"_id" : "testSet",
2010-07-28 10:25:31 -04:00
"members" : [
{"_id" : 0, "host" : nodenames[0], "priority" : 1},
{"_id" : 1, "host" : nodenames[1], "priority" : 2},
{"_id" : 2, "host" : nodenames[2], "priority" : 3}]});
2010-07-28 10:25:31 -04:00
// 2 should be master (give this a while to happen, as 0 will be elected, then demoted)
replTest.waitForState(nodes[2], ReplSetTest.State.PRIMARY, 120000);
2010-07-28 10:25:31 -04:00
// kill 2, 1 should take over
replTest.stop(2);
2010-07-28 10:25:31 -04:00
// 1 should eventually be master
replTest.waitForState(nodes[1], ReplSetTest.State.PRIMARY, 60000);
// do some writes on 1
var master = replTest.getPrimary();
for (var i=0; i<1000; i++) {
master.getDB("foo").bar.insert({i:i});
}
2010-07-28 10:25:31 -04:00
for (i=0; i<1000; i++) {
master.getDB("bar").baz.insert({i:i});
}
// bring 2 back up, 2 should wait until caught up and then become master
replTest.restart(2);
replTest.waitForState(nodes[2], ReplSetTest.State.PRIMARY, 60000);
// make sure nothing was rolled back
master = replTest.getPrimary();
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);
}
}());