mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
SERVER-470 complete setup for parallel clients in separate js scopes
This commit is contained in:
parent
e88f0fdf45
commit
33cd7bc1e1
@ -31,4 +31,4 @@ test = function() {
|
||||
);
|
||||
}
|
||||
|
||||
assert.parallelTests( test, argvs, "one or more tests failed" );
|
||||
assert.parallelTests( test, argvs, "one or more tests failed", true );
|
||||
|
@ -254,10 +254,6 @@ int _main(int argc, char* argv[]) {
|
||||
|
||||
mongo::shellUtils::RecordMyLocation( argv[ 0 ] );
|
||||
|
||||
mongo::ScriptEngine::setup();
|
||||
mongo::globalScriptEngine->setScopeInitCallback( mongo::shellUtils::initScope );
|
||||
auto_ptr< mongo::Scope > scope( mongo::globalScriptEngine->newScope() );
|
||||
|
||||
string url = "test";
|
||||
string dbhost;
|
||||
string port;
|
||||
@ -268,7 +264,7 @@ int _main(int argc, char* argv[]) {
|
||||
|
||||
bool runShell = false;
|
||||
bool nodb = false;
|
||||
|
||||
|
||||
string script;
|
||||
|
||||
po::options_description shell_options("options");
|
||||
@ -364,23 +360,20 @@ int _main(int argc, char* argv[]) {
|
||||
|
||||
if ( !nodb ) { // connect to db
|
||||
cout << "url: " << url << endl;
|
||||
string setup = (string)"db = connect( \"" + fixHost( url , dbhost , port ) + "\")";
|
||||
if ( ! scope->exec( setup , "(connect)" , false , true , false ) )
|
||||
return -1;
|
||||
mongo::shellUtils::_dbConnect = (string)"db = connect( \"" + fixHost( url , dbhost , port ) + "\")";
|
||||
|
||||
if ( username.size() && password.size() ){
|
||||
stringstream ss;
|
||||
ss << "if ( ! db.auth( \"" << username << "\" , \"" << password << "\" ) ){ throw 'login failed'; }";
|
||||
|
||||
if ( ! scope->exec( ss.str() , "(auth)" , true , true , false ) ){
|
||||
cout << "login failed" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
mongo::shellUtils::_dbAuth = ss.str();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mongo::ScriptEngine::setup();
|
||||
mongo::globalScriptEngine->setScopeInitCallback( mongo::shellUtils::initScope );
|
||||
auto_ptr< mongo::Scope > scope( mongo::globalScriptEngine->newScope() );
|
||||
|
||||
if ( !script.empty() ) {
|
||||
mongo::shellUtils::MongoProgramScope s;
|
||||
if ( ! scope->exec( script , "(shell eval)" , true , true , false ) )
|
||||
|
@ -27,6 +27,9 @@ namespace mongo {
|
||||
|
||||
namespace shellUtils {
|
||||
|
||||
std::string _dbConnect;
|
||||
std::string _dbAuth;
|
||||
|
||||
const char *argv0 = 0;
|
||||
void RecordMyLocation( const char *_argv0 ) { argv0 = _argv0; }
|
||||
|
||||
@ -503,6 +506,13 @@ namespace mongo {
|
||||
scope.externalSetup();
|
||||
mongo::shellUtils::installShellUtils( scope );
|
||||
scope.execSetup( jsconcatcode_server , "setupServerCode" );
|
||||
|
||||
if ( !_dbConnect.empty() ) {
|
||||
massert( 12513, "connect failed", scope.exec( _dbConnect , "(connect)" , false , true , false ) );
|
||||
if ( !_dbAuth.empty() ) {
|
||||
massert( 12514, "login failed", scope.exec( _dbAuth , "(auth)" , true , true , false ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,9 @@ namespace mongo {
|
||||
|
||||
namespace shellUtils {
|
||||
|
||||
extern std::string _dbConnect;
|
||||
extern std::string _dbAuth;
|
||||
|
||||
void RecordMyLocation( const char *_argv0 );
|
||||
void installShellUtils( Scope& scope );
|
||||
|
||||
|
@ -373,22 +373,33 @@ if ( typeof _threadInject != "undefined" ){
|
||||
}
|
||||
|
||||
// argvs: array of argv arrays - test will be called for each entry in argvs
|
||||
assert.parallelTests = function( test, argvs, msg ) {
|
||||
assert.parallelTests = function( test, argvs, msg, newScopes ) {
|
||||
newScopes = newScopes || false;
|
||||
var wrapper = function( fun, argv ) {
|
||||
return function() {
|
||||
var __parallelTests__passed = false;
|
||||
try {
|
||||
fun.apply( 0, argv );
|
||||
__parallelTests__passed = true;
|
||||
} catch ( e ) {
|
||||
print( e );
|
||||
}
|
||||
return __parallelTests__passed;
|
||||
}
|
||||
eval (
|
||||
"var z = function() {" +
|
||||
"var fun = " + fun.toString() + ";" +
|
||||
"var argv = " + tojson( argv ) + ";" +
|
||||
"var __parallelTests__passed = false;" +
|
||||
"try {" +
|
||||
"fun.apply( 0, argv );" +
|
||||
"__parallelTests__passed = true;" +
|
||||
"} catch ( e ) {" +
|
||||
"print( e );" +
|
||||
"}" +
|
||||
"return __parallelTests__passed;" +
|
||||
"}"
|
||||
);
|
||||
return z;
|
||||
}
|
||||
var runners = new Array();
|
||||
for( var i in argvs ) {
|
||||
runners.push( fork( wrapper( test, argvs[ i ] ) ) );
|
||||
var t;
|
||||
if ( newScopes )
|
||||
t = new ScopedThread( wrapper( test, argvs[ i ] ) );
|
||||
else
|
||||
t = new Thread( wrapper( test, argvs[ i ] ) );
|
||||
runners.push( t );
|
||||
}
|
||||
|
||||
runners.forEach( function( x ) { x.start(); } );
|
||||
|
Loading…
Reference in New Issue
Block a user