Files
mongo/jstests/replsets/replset_remove_node.js
2010-07-29 14:29:20 -04:00

58 lines
1.8 KiB
JavaScript

doTest = function( signal ) {
// 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.
var replTest = new ReplSetTest( {name: 'testSet', nodes: 3} );
// call startSet() to start each mongod in the replica set
// this returns a list of nodes
var nodes = replTest.startSet();
// Call initiate() to send the replSetInitiate command
// This will wait for initiation
replTest.initiate();
// Call getMaster to return a reference to the node that's been
// elected master.
var master = replTest.getMaster();
// Reconfigure the set, removing the unwanted node
slaveId = replTest.getNodeId( replTest.liveNodes.slaves[0] );
// Shut down the unwanted node
replTest.stop( slaveId );
// Remove that node from the configuration
replTest.remove( slaveId );
// Then, reinitiate
replTest.reInitiate();
// Make sure that a new master comes up
master = replTest.getMaster();
slaves = replTest.liveNodes.slaves;
// Do a status check on each node
// Master should be set to 1 (primary)
assert.soon(function() {
stat = master.getDB("admin").runCommand({replSetGetStatus: 1});
printjson( stat );
return stat.myState == 1;
}, "Master failed to come up as master.");
// Slaves to be set to 2 (secondary)
assert.soon(function() {
stat = slaves[0].getDB("admin").runCommand({replSetGetStatus: 1});
return stat.myState == 2;
}, "Slave failed to come up as slave.");
assert.soon(function() {
stat = slaves[0].getDB("admin").runCommand({replSetGetStatus: 1});
return stat.members.length == 2;
}, "Wrong number of members");
}
doTest( 15 );