Skip to content

Commit 5f837c7

Browse files
committed
more arbiter cases
1 parent fd780da commit 5f837c7

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

jstests/repl/pair3.js

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ connect = function() {
1616
startMongoProgram( "mongobridge", "--port", rpPort, "--dest", "localhost:" + rPort );
1717
}
1818

19-
doTest = function() {
19+
doTest1 = function() {
2020
ports = allocatePorts( 7 );
2121
aPort = ports[ 0 ];
2222
alPort = ports[ 1 ];
@@ -181,6 +181,71 @@ doTest = function() {
181181
return ( rm == 0 );
182182
} );
183183

184+
ports.forEach( function( x ) { stopMongoProgram( x ); } );
184185
}
185186

186-
doTest();
187+
// this time don't start connected
188+
doTest2 = function() {
189+
ports = allocatePorts( 7 );
190+
aPort = ports[ 0 ];
191+
alPort = ports[ 1 ];
192+
arPort = ports[ 2 ];
193+
lPort = ports[ 3 ];
194+
lpPort = ports[ 4 ];
195+
rPort = ports[ 5 ];
196+
rpPort = ports[ 6 ];
197+
198+
a = startMongod( "--port", aPort, "--dbpath", "/data/db/" + baseName + "-arbiter", "--nohttpinterface" );
199+
l = startMongod( "--port", lPort, "--dbpath", "/data/db/" + baseName + "-left", "--pairwith", "127.0.0.1:" + rpPort, "127.0.0.1:" + alPort, "--oplogSize", "1", "--nohttpinterface" );
200+
r = startMongod( "--port", rPort, "--dbpath", "/data/db/" + baseName + "-right", "--pairwith", "127.0.0.1:" + lpPort, "127.0.0.1:" + arPort, "--oplogSize", "1", "--nohttpinterface" );
201+
202+
assert.soon( function() {
203+
lm = ismaster( l );
204+
rm = ismaster( r );
205+
206+
assert( lm == -1 || lm == -3, "lm value invalid" );
207+
assert( rm == -1 || rm == -3, "rm value invalid" );
208+
209+
return ( lm == -3 && rm == -3 );
210+
} );
211+
212+
startMongoProgram( "mongobridge", "--port", arPort, "--dest", "localhost:" + aPort );
213+
214+
// there hasn't been an initial sync, no no node will become master
215+
216+
for( i = 0; i < 10; ++i ) {
217+
assert( ismaster( l ) == -3 && ismaster( r ) == -3 );
218+
sleep( 500 );
219+
}
220+
221+
stopMongoProgram( arPort );
222+
223+
startMongoProgram( "mongobridge", "--port", alPort, "--dest", "localhost:" + aPort );
224+
225+
for( i = 0; i < 10; ++i ) {
226+
assert( ismaster( l ) == -3 && ismaster( r ) == -3 );
227+
sleep( 500 );
228+
}
229+
230+
stopMongoProgram( alPort );
231+
232+
// connect l and r without a
233+
234+
startMongoProgram( "mongobridge", "--port", lpPort, "--dest", "localhost:" + lPort );
235+
startMongoProgram( "mongobridge", "--port", rpPort, "--dest", "localhost:" + rPort );
236+
237+
assert.soon( function() {
238+
lm = ismaster( l );
239+
rm = ismaster( r );
240+
241+
assert( lm == 0 || lm == -3, "lm value invalid" );
242+
assert( rm == 1 || rm == -3 || rm == 0, "rm value invalid" );
243+
244+
return ( lm == 0 && rm == 1 );
245+
} );
246+
247+
ports.forEach( function( x ) { stopMongoProgram( x ); } );
248+
}
249+
250+
doTest1();
251+
doTest2();

0 commit comments

Comments
 (0)