3
var baseName = "jstests_pair3test";
5
ismaster = function( n ) {
6
var im = n.getDB( "admin" ).runCommand( { "ismaster" : 1 } );
7
print( "ismaster: " + tojson( im ) );
8
assert( im, "command ismaster failed" );
12
// bring up node connections before arbiter connections so that arb can forward to node when expected
13
connect = function() {
15
lp = startMongoProgram( "mongobridge", "--port", lpPort, "--dest", "localhost:" + lPort );
18
rp = startMongoProgram( "mongobridge", "--port", rpPort, "--dest", "localhost:" + rPort );
21
al = startMongoProgram( "mongobridge", "--port", alPort, "--dest", "localhost:" + aPort );
24
ar = startMongoProgram( "mongobridge", "--port", arPort, "--dest", "localhost:" + aPort );
28
disconnectNode = function( mongo ) {
30
stopMongoProgram( lpPort );
34
stopMongoProgram( rpPort );
37
if ( mongo.host.match( new RegExp( "^127.0.0.1:" + lPort + "$" ) ) ) {
38
stopMongoProgram( alPort );
40
} else if ( mongo.host.match( new RegExp( "^127.0.0.1:" + rPort + "$" ) ) ) {
41
stopMongoProgram( arPort );
44
assert( false, "don't know how to disconnect node: " + mongo );
48
doTest1 = function() {
49
al = ar = lp = rp = null;
50
ports = allocatePorts( 7 );
61
a = new MongodRunner( aPort, "/data/db/" + baseName + "-arbiter" );
62
l = new MongodRunner( lPort, "/data/db/" + baseName + "-left", "127.0.0.1:" + rpPort, "127.0.0.1:" + alPort );
63
r = new MongodRunner( rPort, "/data/db/" + baseName + "-right", "127.0.0.1:" + lpPort, "127.0.0.1:" + arPort );
65
pair = new ReplPair( l, r, a );
69
pair.waitForSteadyState();
72
disconnectNode( pair.slave() );
73
pair.waitForSteadyState( [ 1, -3 ], pair.master().host );
76
disconnectNode( pair.master() );
77
pair.waitForSteadyState( [ -3, -3 ] );
81
pair.waitForSteadyState();
84
disconnectNode( pair.master() );
85
pair.waitForSteadyState( [ 1, -3 ], pair.slave().host, true );
87
// disconnect new master
88
disconnectNode( pair.master() );
89
pair.waitForSteadyState( [ -3, -3 ] );
93
pair.waitForSteadyState();
96
disconnectNode( pair.slave() );
97
pair.waitForSteadyState( [ 1, -3 ], pair.master().host );
101
pair.waitForSteadyState( [ 1, 0 ], pair.master().host );
104
disconnectNode( pair.master() );
105
pair.waitForSteadyState( [ 1, -3 ], pair.slave().host, true );
107
// reconnect old master
109
pair.waitForSteadyState( [ 1, 0 ], pair.master().host );
111
ports.forEach( function( x ) { stopMongoProgram( x ); } );
114
// this time don't start connected
115
doTest2 = function() {
116
al = ar = lp = rp = null;
117
ports = allocatePorts( 7 );
126
a = new MongodRunner( aPort, "/data/db/" + baseName + "-arbiter" );
127
l = new MongodRunner( lPort, "/data/db/" + baseName + "-left", "127.0.0.1:" + rpPort, "127.0.0.1:" + alPort );
128
r = new MongodRunner( rPort, "/data/db/" + baseName + "-right", "127.0.0.1:" + lpPort, "127.0.0.1:" + arPort );
130
pair = new ReplPair( l, r, a );
132
pair.waitForSteadyState( [ -3, -3 ] );
134
startMongoProgram( "mongobridge", "--port", arPort, "--dest", "localhost:" + aPort );
136
// there hasn't been an initial sync, no no node will become master
138
for( i = 0; i < 10; ++i ) {
139
assert( pair.isMaster( pair.right() ) == -3 && pair.isMaster( pair.left() ) == -3 );
143
stopMongoProgram( arPort );
145
startMongoProgram( "mongobridge", "--port", alPort, "--dest", "localhost:" + aPort );
147
for( i = 0; i < 10; ++i ) {
148
assert( pair.isMaster( pair.right() ) == -3 && pair.isMaster( pair.left() ) == -3 );
152
stopMongoProgram( alPort );
154
// connect l and r without a
156
startMongoProgram( "mongobridge", "--port", lpPort, "--dest", "localhost:" + lPort );
157
startMongoProgram( "mongobridge", "--port", rpPort, "--dest", "localhost:" + rPort );
159
pair.waitForSteadyState( [ 1, 0 ] );
161
ports.forEach( function( x ) { stopMongoProgram( x ); } );
164
// recover from master - master setup
165
doTest3 = function() {
166
al = ar = lp = rp = null;
167
ports = allocatePorts( 7 );
178
a = new MongodRunner( aPort, "/data/db/" + baseName + "-arbiter" );
179
l = new MongodRunner( lPort, "/data/db/" + baseName + "-left", "127.0.0.1:" + rpPort, "127.0.0.1:" + alPort );
180
r = new MongodRunner( rPort, "/data/db/" + baseName + "-right", "127.0.0.1:" + lpPort, "127.0.0.1:" + arPort );
182
pair = new ReplPair( l, r, a );
184
pair.waitForSteadyState();
186
// now can only talk to arbiter
187
stopMongoProgram( lpPort );
188
stopMongoProgram( rpPort );
189
pair.waitForSteadyState( [ 1, 1 ], null, true );
192
startMongoProgram( "mongobridge", "--port", lpPort, "--dest", "localhost:" + lPort );
193
startMongoProgram( "mongobridge", "--port", rpPort, "--dest", "localhost:" + rPort );
194
pair.waitForSteadyState( [ 1, 0 ], null, true );
196
ports.forEach( function( x ) { stopMongoProgram( x ); } );
199
// check that initial sync is persistent
200
doTest4 = function( signal ) {
201
al = ar = lp = rp = null;
202
ports = allocatePorts( 7 );
213
a = new MongodRunner( aPort, "/data/db/" + baseName + "-arbiter" );
214
l = new MongodRunner( lPort, "/data/db/" + baseName + "-left", "127.0.0.1:" + rpPort, "127.0.0.1:" + alPort );
215
r = new MongodRunner( rPort, "/data/db/" + baseName + "-right", "127.0.0.1:" + lpPort, "127.0.0.1:" + arPort );
217
pair = new ReplPair( l, r, a );
219
pair.waitForSteadyState();
221
pair.killNode( pair.left(), signal );
222
pair.killNode( pair.right(), signal );
223
stopMongoProgram( rpPort );
224
stopMongoProgram( lpPort );
226
// now can only talk to arbiter
228
pair.waitForSteadyState( [ 1, 1 ], null, true );