0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/jstests/repl/pair2.js

72 lines
2.2 KiB
JavaScript
Raw Normal View History

2009-02-02 15:54:00 +01:00
// Pairing resync
var baseName = "jstests_pair2test";
ismaster = function( n ) {
im = n.getDB( "admin" ).runCommand( { "ismaster" : 1 } );
assert( im );
return im.ismaster;
}
soonCount = function( m, count ) {
assert.soon( function() {
// print( "counting" );
//// print( "counted: " + l.getDB( baseName ).z.find().count() );
return m.getDB( baseName ).z.find().count() == count;
} );
}
doTest = function( signal ) {
2009-04-02 00:21:07 +02:00
ports = allocatePorts( 3 );
a = new MongodRunner( ports[ 0 ], "/data/db/" + baseName + "-arbiter" );
l = new MongodRunner( ports[ 1 ], "/data/db/" + baseName + "-left", "127.0.0.1:" + ports[ 2 ], "127.0.0.1:" + ports[ 0 ] );
r = new MongodRunner( ports[ 2 ], "/data/db/" + baseName + "-right", "127.0.0.1:" + ports[ 1 ], "127.0.0.1:" + ports[ 0 ] );
rp = new ReplPair( l, r, a );
rp.start();
rp.waitForSteadyState();
rp.slave().setSlaveOk();
mz = rp.master().getDB( baseName ).z;
mz.save( { _id: new ObjectId() } );
soonCount( rp.slave(), 1 );
assert.eq( 0, rp.slave().getDB( "admin" ).runCommand( { "resync" : 1 } ).ok );
2009-04-15 22:52:39 +02:00
sleep( 3000 ); // allow time to finish clone and save ReplSource
rp.killNode( rp.slave(), signal );
rp.waitForSteadyState( [ 1, null ], rp.master().host );
big = new Array( 2000 ).toString();
for( i = 0; i < 1000; ++i )
mz.save( { _id: new ObjectId(), i: i, b: big } );
2009-04-23 19:05:03 +02:00
rp.start( true );
rp.waitForSteadyState( [ 1, 0 ], rp.master().host );
2009-04-23 19:05:03 +02:00
sleep( 15000 );
rp.slave().setSlaveOk();
2009-04-15 22:52:39 +02:00
assert.soon( function() {
ret = rp.slave().getDB( "admin" ).runCommand( { "resync" : 1 } );
2009-04-15 22:52:39 +02:00
// printjson( ret );
return 1 == ret.ok;
} );
sleep( 8000 );
soonCount( rp.slave(), 1001 );
sz = rp.slave().getDB( baseName ).z
assert.eq( 1, sz.find( { i: 0 } ).count() );
assert.eq( 1, sz.find( { i: 999 } ).count() );
assert.eq( 0, rp.slave().getDB( "admin" ).runCommand( { "resync" : 1 } ).ok );
ports.forEach( function( x ) { stopMongod( x ); } );
}
2009-02-02 15:54:00 +01:00
doTest( 15 ); // SIGTERM
doTest( 9 ); // SIGKILL