0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-29 16:47:28 +01:00

SERVER-643 prevent test failures involving mongobridge, be more careful about potentially reused uris

This commit is contained in:
Aaron 2010-02-22 12:45:58 -08:00
parent cd1dfe32b0
commit 3dfbf854da
3 changed files with 22 additions and 5 deletions

View File

@ -80,7 +80,12 @@ void intr( int sig ){
#if !defined(_WIN32)
void killOps() {
mongo::BSONObj spec = BSON( "" << mongo::shellUtils::_allMyUris );
if ( mongo::shellUtils::_nokillop )
return;
vector< string > uris;
for( map< const void*, string >::iterator i = mongo::shellUtils::_allMyUris.begin(); i != mongo::shellUtils::_allMyUris.end(); ++i )
uris.push_back( i->second );
mongo::BSONObj spec = BSON( "" << uris );
auto_ptr< mongo::Scope > scope( mongo::globalScriptEngine->newScope() );
scope->invoke( "function( x ) { killWithUris( x ); }", spec );
}
@ -313,6 +318,7 @@ int _main(int argc, char* argv[]) {
hidden_options.add_options()
("dbaddress", po::value<string>(), "dbaddress")
("files", po::value< vector<string> >(), "files")
("nokillop", "nokillop") // for testing, kill op will also be disabled automatically if the tests starts a mongo program
;
positional_options.add("dbaddress", 1);
@ -360,7 +366,10 @@ int _main(int argc, char* argv[]) {
if (params.count("quiet")) {
mongo::cmdLine.quiet = true;
}
if (params.count("nokillop")) {
mongo::shellUtils::_nokillop = true;
}
/* This is a bit confusing, here are the rules:
*
* if nodb is set then all positional parameters are files

View File

@ -431,6 +431,7 @@ namespace mongo {
#endif
}
BSONObj StartMongoProgram( const BSONObj &a ) {
_nokillop = true;
ProgramRunner r( a );
r.start();
boost::thread t( r );
@ -689,11 +690,17 @@ namespace mongo {
}
}
vector< string > _allMyUris;
map< const void*, string > _allMyUris;
bool _nokillop = false;
void onConnect( DBClientWithCommands &c ) {
if ( _nokillop ) {
return;
}
BSONObj info;
uassert( 13010, "whatsmyuri failed", c.runCommand( "admin", BSON( "whatsmyuri" << 1 ), info ) );
_allMyUris.push_back( info[ "you" ].str() );
// There's no way to explicitly disconnect a DBClientConnection, but we might allocate
// a new uri on automatic reconnect. So just store one uri per connection.
_allMyUris[ &c ] = info[ "you" ].str();
}
}
}

View File

@ -26,7 +26,8 @@ namespace mongo {
extern std::string _dbConnect;
extern std::string _dbAuth;
extern vector< string > _allMyUris;
extern map< const void*, string > _allMyUris;
extern bool _nokillop;
void RecordMyLocation( const char *_argv0 );
void installShellUtils( Scope& scope );