blob: d9f5093783d91a2ac7b91f8cfbe7725b0d824370 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
doTest = function( signal ) {
// Make sure that we can restart a replica set completely
// 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();
// Now we're going to shut down all nodes
mId = replTest.getNodeId( master );
s1Id = replTest.getNodeId( replTest.liveNodes.slaves[0] );
s2Id = replTest.getNodeId( replTest.liveNodes.slaves[1] );
replTest.stop( s1Id );
replTest.stop( s2Id );
assert.soon(function() {
var status = master.getDB("admin").runCommand({replSetGetStatus: 1});
return status.members[1].state == 8 && status.members[2].state == 8;
});
replTest.stop( mId );
// Now let's restart these nodes
replTest.restart( mId );
replTest.restart( s1Id );
replTest.restart( s2Id );
// Make sure that a new master comes up
master = replTest.getMaster();
slaves = replTest.liveNodes.slaves;
assert.soon(function() {
var status = master.getDB("admin").runCommand({replSetGetStatus: 1});
return status.members[1].state != 8 && status.members[2].state != 8;
});
// Do a status check on each node
// Master should be set to 1 (primary)
assert.soon(function() {
stat = master.getDB("admin").runCommand({replSetGetStatus: 1});
return stat.myState == 1;
});
// Slaves to be set to 2 (secondary)
assert.soon(function() {
stat = slaves[0].getDB("admin").runCommand({replSetGetStatus: 1});
return stat.myState == 2;
});
assert.soon(function() {
stat = slaves[1].getDB("admin").runCommand({replSetGetStatus: 1});
return stat.myState == 2;
});
}
doTest( 15 );
|