summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/auth/auth1.js3
-rw-r--r--jstests/auth/auth3.js8
-rw-r--r--jstests/auth/localhostAuthBypass.js26
-rw-r--r--jstests/auth/logout_reconnect.js5
-rw-r--r--jstests/auth/server-4892.js23
-rw-r--r--jstests/disk/directoryperdb.js5
-rw-r--r--jstests/disk/filesize.js12
-rw-r--r--jstests/disk/killall.js8
-rw-r--r--jstests/disk/norepeat.js61
-rw-r--r--jstests/disk/repair.js41
-rw-r--r--jstests/disk/repair2.js95
-rw-r--r--jstests/disk/repair3.js33
-rw-r--r--jstests/disk/repair4.js17
-rw-r--r--jstests/dur/checksum.js2
-rw-r--r--jstests/dur/dropdb.js2
-rw-r--r--jstests/dur/dur_jscore_passthrough.js3
-rw-r--r--jstests/fail_point/fail_point.js2
-rw-r--r--jstests/gle/get_last_error.js7
-rw-r--r--jstests/libs/slow_weekly_util.js5
-rw-r--r--jstests/libs/ssl_test.js5
-rw-r--r--jstests/noPassthrough/dir_per_db_and_split.js13
-rw-r--r--jstests/noPassthrough/directoryperdb.js6
-rw-r--r--jstests/noPassthrough/split_collections_and_indexes.js12
-rw-r--r--jstests/noPassthrough/ttl_capped.js7
-rw-r--r--jstests/noPassthrough/wt_nojournal_fsync.js1
-rw-r--r--jstests/noPassthroughWithMongod/httpinterface.js9
-rw-r--r--jstests/noPassthroughWithMongod/index_no_retry.js10
-rw-r--r--jstests/noPassthroughWithMongod/index_retry.js10
-rw-r--r--jstests/noPassthroughWithMongod/ipv6_connection_string_validation.js10
-rw-r--r--jstests/noPassthroughWithMongod/server7428.js10
-rw-r--r--jstests/noPassthroughWithMongod/sharding_rs_arb1.js3
-rw-r--r--jstests/noPassthroughWithMongod/unix_socket1.js7
-rw-r--r--jstests/replsets/initial_sync3.js14
-rw-r--r--jstests/replsets/stepdown.js6
-rw-r--r--jstests/replsets/tags.js2
-rw-r--r--jstests/replsets/tags2.js2
-rw-r--r--jstests/replsets/tags_with_reconfig.js2
-rw-r--r--jstests/sharding/addshard2.js47
-rw-r--r--jstests/sharding/addshard3.js6
-rw-r--r--jstests/sharding/addshard4.js4
-rw-r--r--jstests/sharding/auth.js100
-rw-r--r--jstests/sharding/csrs_upgrade.js6
-rw-r--r--jstests/sharding/diffservers1.js10
-rw-r--r--jstests/sharding/names.js4
-rw-r--r--jstests/sharding/remove2.js5
-rw-r--r--jstests/sharding/sync_cluster_config/configdb_str.js4
-rw-r--r--jstests/sharding/sync_cluster_config/rs_stepdown_and_pooling.js4
-rw-r--r--jstests/sharding/sync_cluster_config/sync7.js2
-rw-r--r--jstests/sharding/version1.js4
-rw-r--r--jstests/sharding/version2.js17
-rw-r--r--jstests/ssl/set_parameter_ssl.js32
-rw-r--r--jstests/ssl/ssl_cert_password.js18
-rw-r--r--jstests/ssl/ssl_fips.js7
-rw-r--r--jstests/ssl/ssl_hostname_validation.js27
-rw-r--r--jstests/ssl/x509_client.js6
-rw-r--r--jstests/sslSpecial/set_parameter_nossl.js12
-rw-r--r--jstests/tool/oplog_all_ops.js10
-rw-r--r--src/mongo/shell/replsetbridge.js6
-rw-r--r--src/mongo/shell/replsettest.js92
-rwxr-xr-xsrc/mongo/shell/servers.js103
-rw-r--r--src/mongo/shell/servers_misc.js39
-rw-r--r--src/mongo/shell/shardingtest.js231
62 files changed, 653 insertions, 630 deletions
diff --git a/jstests/auth/auth1.js b/jstests/auth/auth1.js
index 32628e8bf57..a15d4a46995 100644
--- a/jstests/auth/auth1.js
+++ b/jstests/auth/auth1.js
@@ -3,12 +3,9 @@
function setupTest() {
print("START auth1.js");
-
- port = allocatePorts( 1 )[ 0 ];
baseName = "jstests_auth_auth1";
m = MongoRunner.runMongod({auth: "",
- port: port,
nohttpinterface: "",
bind_ip: "127.0.0.1",
useHostname: false});
diff --git a/jstests/auth/auth3.js b/jstests/auth/auth3.js
index 2f28111da24..fde160d06ce 100644
--- a/jstests/auth/auth3.js
+++ b/jstests/auth/auth3.js
@@ -1,4 +1,8 @@
-var conn = MongoRunner.runMongod({auth : "", port : 31001});
+(function() {
+
+'use strict'
+
+var conn = MongoRunner.runMongod({ auth: "" });
var admin = conn.getDB("admin");
var errorCodeUnauthorized = 13;
@@ -24,3 +28,5 @@ conn.getDB("admin").auth("foo","bar");
assert("inprog" in admin.currentOp());
assert("info" in admin.killOp(123));
assert.eq(admin.fsyncUnlock().errmsg, "not locked");
+
+})();
diff --git a/jstests/auth/localhostAuthBypass.js b/jstests/auth/localhostAuthBypass.js
index b3b40598015..1b07456fbe3 100644
--- a/jstests/auth/localhostAuthBypass.js
+++ b/jstests/auth/localhostAuthBypass.js
@@ -7,8 +7,6 @@ var baseName = "auth_server-6591";
var dbpath = MongoRunner.dataPath + baseName;
var username = "foo";
var password = "bar";
-var port = allocatePorts(1)[0];
-var host = "localhost:" + port;
load("jstests/libs/host_ipaddr.js");
@@ -101,18 +99,18 @@ var authenticate = function(mongo) {
mongo.getDB("admin").auth(username, password);
};
-var shutdown = function(mongo) {
+var shutdown = function(conn) {
print("============ shutting down.");
- MongoRunner.stopMongod(port, /*signal*/false, { auth: { user: username, pwd: password}});
+ MongoRunner.stopMongod(conn.port, /*signal*/false, { auth: { user: username, pwd: password}});
};
var runTest = function(useHostName) {
print("==========================");
print("starting mongod: useHostName=" + useHostName);
print("==========================");
- MongoRunner.runMongod({auth: "", port: port, dbpath: dbpath, useHostName: useHostName});
+ var conn = MongoRunner.runMongod({auth: "", dbpath: dbpath, useHostName: useHostName});
- var mongo = new Mongo(host);
+ var mongo = new Mongo("localhost:" + conn.port);
assertCannotRunCommands(mongo);
@@ -125,7 +123,7 @@ var runTest = function(useHostName) {
assertCanRunCommands(mongo);
print("============ reconnecting with new client.");
- mongo = new Mongo(host);
+ mongo = new Mongo("localhost:" + conn.port);
assertCannotRunCommands(mongo);
@@ -133,26 +131,26 @@ var runTest = function(useHostName) {
assertCanRunCommands(mongo);
- shutdown(mongo);
+ shutdown(conn);
};
-var runNonlocalTest = function(hostPort) {
+var runNonlocalTest = function(host) {
print("==========================");
- print("starting mongod: non-local host access "+hostPort);
+ print("starting mongod: non-local host access " + host);
print("==========================");
- MongoRunner.runMongod({auth: "", port: port, dbpath: dbpath});
+ var conn = MongoRunner.runMongod({auth: "", dbpath: dbpath});
- var mongo = new Mongo(hostPort);
+ var mongo = new Mongo(host + ":" + conn.port);
assertCannotRunCommands(mongo);
assert.throws(function() { mongo.getDB("admin").createUser
({ user:username, pwd: password, roles: jsTest.adminUserRoles }); });
assert.throws(function() { mongo.getDB("$external").createUser
({ user:username, pwd: password, roles: jsTest.adminUserRoles }); });
- shutdown(mongo);
+ shutdown(conn);
};
runTest(false);
runTest(true);
-runNonlocalTest(get_ipaddr()+":"+port);
+runNonlocalTest(get_ipaddr());
diff --git a/jstests/auth/logout_reconnect.js b/jstests/auth/logout_reconnect.js
index 20d46836780..119284ce9d4 100644
--- a/jstests/auth/logout_reconnect.js
+++ b/jstests/auth/logout_reconnect.js
@@ -4,11 +4,8 @@
* It is a regression test for SERVER-8798.
*/
-port = allocatePorts( 1 )[ 0 ];
-
-conn = MongoRunner.runMongod({
+var conn = MongoRunner.runMongod({
auth : "",
- port : port,
remember : true
});
diff --git a/jstests/auth/server-4892.js b/jstests/auth/server-4892.js
index 12fc0d8c067..3053fcab4dc 100644
--- a/jstests/auth/server-4892.js
+++ b/jstests/auth/server-4892.js
@@ -7,24 +7,25 @@
var baseName = 'jstests_auth_server4892';
var dbpath = MongoRunner.dataPath + baseName;
-var port = allocatePorts( 1 )[ 0 ];
-var mongod_common_args = [
- '--port', port, '--dbpath', dbpath, '--bind_ip', '127.0.0.1', '--nohttpinterface' ];
+resetDbpath(dbpath);
+var mongodCommonArgs = {
+ dbpath: dbpath,
+ noCleanData: true,
+};
/*
* Start an instance of mongod, pass it as a parameter to operation(), then stop the instance of
* mongod before unwinding or returning out of with_mongod().
*
- * extra_mongod_args are extra arguments to pass on the mongod command line, in an Array.
+ * 'extraMongodArgs' are extra arguments to pass on the mongod command line, as an object.
*/
-function with_mongod( extra_mongod_args, operation ) {
- var mongod = startMongoProgram.apply(
- null, ['mongod'].concat( mongod_common_args, extra_mongod_args ) );
+function withMongod(extraMongodArgs, operation) {
+ var mongod = MongoRunner.runMongod(Object.merge(mongodCommonArgs, extraMongodArgs));
try {
operation( mongod );
} finally {
- MongoRunner.stopMongod( port );
+ MongoRunner.stopMongod( mongod.port );
}
}
@@ -42,9 +43,7 @@ function expectNumLiveCursors(mongod, expectedNumLiveCursors) {
+ expectedNumLiveCursors + ")");
}
-resetDbpath( dbpath );
-
-with_mongod( ['--noauth'], function setupTest( mongod ) {
+withMongod({noauth: ""}, function setupTest(mongod) {
var admin, somedb, conn;
conn = new Mongo( mongod.host );
admin = conn.getDB( 'admin' );
@@ -59,7 +58,7 @@ with_mongod( ['--noauth'], function setupTest( mongod ) {
admin.logout();
} );
-with_mongod( ['--auth'], function runTest( mongod ) {
+withMongod({auth: ""}, function runTest(mongod) {
var conn = new Mongo( mongod.host );
var somedb = conn.getDB( 'somedb' );
somedb.auth('frim', 'fram');
diff --git a/jstests/disk/directoryperdb.js b/jstests/disk/directoryperdb.js
index 157efbd07b6..b6e2ab5f9e5 100644
--- a/jstests/disk/directoryperdb.js
+++ b/jstests/disk/directoryperdb.js
@@ -1,9 +1,6 @@
var baseDir = "jstests_disk_directoryper";
var baseName = "directoryperdb"
-port = allocatePorts( 1 )[ 0 ];
-dbpath = MongoRunner.dataPath + baseDir + "/";
-
-
+var dbpath = MongoRunner.dataPath + baseDir + "/";
var storageEngine = db.serverStatus().storageEngine.name;
// The pattern which matches the names of database files
diff --git a/jstests/disk/filesize.js b/jstests/disk/filesize.js
index 77295c7b4bd..bb1291c0777 100644
--- a/jstests/disk/filesize.js
+++ b/jstests/disk/filesize.js
@@ -1,9 +1,8 @@
-// test for SERVER-7430: Warning about smallfiles should include filename
-var port = allocatePorts( 1 )[ 0 ];
+// Test for SERVER-7430: Warning about smallfiles should include filename
var baseName = "filesize";
// Start mongod with --smallfiles
-var m = MongoRunner.runMongod({bind_ip: "127.0.0.1", nojournal: "", smallfiles: ""});
+var m = MongoRunner.runMongod({nojournal: "", smallfiles: ""});
var db = m.getDB( baseName );
@@ -14,7 +13,12 @@ if (db.serverBuildInfo().bits == 32) {
// Restart mongod without --smallFiles
MongoRunner.stopMongod(m);
m = MongoRunner.runMongod({
- restart: true, cleanData: false, dbpath: m.dbpath, bind_ip: "127.0.0.1", nojournal: ""});
+ restart: true,
+ cleanData: false,
+ dbpath: m.dbpath,
+ port: m.port,
+ nojournal: "",
+ });
db = m.getDB( baseName );
var log = db.adminCommand( { getLog : "global" } ).log
diff --git a/jstests/disk/killall.js b/jstests/disk/killall.js
index ba294a53504..beb3e99e778 100644
--- a/jstests/disk/killall.js
+++ b/jstests/disk/killall.js
@@ -6,19 +6,17 @@
* would not result in a zero return code.
*/
-var port = allocatePorts( 1 )[ 0 ]
-
var baseName = "jstests_disk_killall";
var dbpath = MongoRunner.dataPath + baseName;
-var mongod = MongoRunner.runMongod({port: port, dbpath: dbpath});
+var mongod = MongoRunner.runMongod({dbpath: dbpath});
var db = mongod.getDB( "test" );
var collection = db.getCollection( baseName );
assert.writeOK(collection.insert({}));
var awaitShell = startParallelShell(
"db." + baseName + ".count( { $where: function() { while( 1 ) { ; } } } )",
- port);
+ mongod.port);
sleep( 1000 );
/**
@@ -36,7 +34,7 @@ exitCode = awaitShell({checkExitSuccess: false});
assert.neq(0, exitCode, "expected shell to exit abnormally due to mongod being terminated");
mongod = MongoRunner.runMongod({
- port: port,
+ port: mongod.port,
restart: true,
cleanData: false,
dbpath: mongod.dbpath
diff --git a/jstests/disk/norepeat.js b/jstests/disk/norepeat.js
deleted file mode 100644
index 1379ff1af20..00000000000
--- a/jstests/disk/norepeat.js
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
-baseName = "jstests_disk_norepeat";
-
-ports = allocatePorts( 1 );
-m = startMongod( "--port", ports[ 0 ], "--deDupMem", "200", "--dbpath", MongoRunner.dataPath + baseName, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
-
-t = m.getDB( baseName ).getCollection( baseName );
-
-t.drop();
-t.ensureIndex( { i: 1 } );
-for( i = 0; i < 3; ++i ) {
- t.save( { i: i } );
-}
-
-c = t.find().hint( { i: 1 } ).limit( 2 );
-assert.eq( 0, c.next().i );
-t.update( { i: 0 }, { i: 3 } );
-assert.eq( 1, c.next().i );
-assert.eq( 2, c.next().i );
-assert.throws( function() { c.next() }, [], "unexpected: object found" );
-
-// now force upgrade to disk storage
-
-t.drop();
-t.ensureIndex( { i: 1 } );
-for( i = 0; i < 10; ++i ) {
- t.save( { i: i } );
-}
-// apparently this means we also request 2 in subsequent getMore's
-c = t.find().hint( {i:1} ).limit( 2 );
-assert.eq( 0, c.next().i );
-t.update( { i: 0 }, { i: 10 } );
-for( i = 1; i < 10; ++i ) {
- if ( i == 7 ) {
- t.update( { i: 6 }, { i: 11 } );
- t.update( { i: 9 }, { i: 12 } );
- }
- if ( i == 9 ) {
- i = 12;
- }
- assert.eq( i, c.next().i );
-}
-assert.throws( function() { c.next() }, [], "unexpected: object found" );
-
-m.getDB( "local" ).getCollectionNames().forEach( function( x ) { assert( !x.match( /^temp/ ), "temp collection found" ); } );
-
-t.drop();
-m.getDB( baseName ).createCollection( baseName, { capped:true, size:100000, autoIndexId:false } );
-t = m.getDB( baseName ).getCollection( baseName );
-t.insert( {_id:"a"} );
-t.insert( {_id:"a"} );
-t.insert( {_id:"a"} );
-
-c = t.find().limit( 2 );
-assert.eq( "a", c.next()._id );
-assert.eq( "a", c.next()._id );
-assert.eq( "a", c.next()._id );
-assert( !c.hasNext() );
-
-assert( t.validate().valid );
-*/
diff --git a/jstests/disk/repair.js b/jstests/disk/repair.js
index 0a92658252b..699dbabf0d8 100644
--- a/jstests/disk/repair.js
+++ b/jstests/disk/repair.js
@@ -1,15 +1,17 @@
// check --repairpath and --repair
var baseName = "jstests_disk_repair";
-
-port = allocatePorts( 1 )[ 0 ];
-dbpath = MongoRunner.dataPath + baseName + "/";
-repairpath = dbpath + "repairDir/"
+var dbpath = MongoRunner.dataPath + baseName + "/";
+var repairpath = dbpath + "repairDir/"
resetDbpath( dbpath );
resetDbpath( repairpath );
-m = startMongoProgram( "mongod", "--port", port, "--dbpath", dbpath, "--repairpath", repairpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+var m = MongoRunner.runMongod({
+ dbpath: dbpath,
+ repairpath: repairpath,
+ noCleanData: true,
+});
db = m.getDB( baseName );
db[ baseName ].save( {} );
assert.commandWorked( db.runCommand( {repairDatabase:1, backupOriginalFiles:true} ) );
@@ -22,26 +24,39 @@ function check() {
assert.eq.automsg( "1", "db[ baseName ].count()" );
}
check();
-MongoRunner.stopMongod( port );
+MongoRunner.stopMongod( m.port );
resetDbpath( repairpath );
-m = startMongoProgram( "mongod", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+m = MongoRunner.runMongod({
+ port: m.port,
+ dbpath: dbpath,
+ noCleanData: true,
+});
db = m.getDB( baseName );
assert.commandWorked( db.runCommand( {repairDatabase:1} ) );
check();
-MongoRunner.stopMongod( port );
+MongoRunner.stopMongod( m.port );
resetDbpath( repairpath );
-rc = runMongoProgram( "mongod", "--repair", "--port", port, "--dbpath", dbpath, "--repairpath", repairpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+rc = runMongoProgram("mongod", "--repair", "--port", m.port, "--dbpath", dbpath,
+ "--repairpath", repairpath);
assert.eq.automsg( "0", "rc" );
-m = startMongoProgram( "mongod", "--port", port, "--dbpath", dbpath, "--repairpath", repairpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+m = MongoRunner.runMongod({
+ port: m.port,
+ dbpath: dbpath,
+ noCleanData: true,
+});
db = m.getDB( baseName );
check();
-MongoRunner.stopMongod( port );
+MongoRunner.stopMongod( m.port );
resetDbpath( repairpath );
-rc = runMongoProgram( "mongod", "--repair", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+rc = runMongoProgram("mongod", "--repair", "--port", m.port, "--dbpath", dbpath);
assert.eq.automsg( "0", "rc" );
-m = startMongoProgram( "mongod", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+m = MongoRunner.runMongod({
+ port: m.port,
+ dbpath: dbpath,
+ noCleanData: true,
+});
db = m.getDB( baseName );
check();
diff --git a/jstests/disk/repair2.js b/jstests/disk/repair2.js
index a582d06a0ec..9a8da991f2d 100644
--- a/jstests/disk/repair2.js
+++ b/jstests/disk/repair2.js
@@ -12,16 +12,20 @@ function check() {
assert.eq.automsg( "1", "db[ baseName ].count()" );
}
-port = allocatePorts( 1 )[ 0 ];
-dbpath = MongoRunner.dataPath + baseName + "/";
-repairpath = dbpath + "repairDir/";
-longDBName = Array(61).join('a');
-longRepairPath = dbpath + Array(61).join('b') + '/';
+var dbpath = MongoRunner.dataPath + baseName + "/";
+var repairpath = dbpath + "repairDir/";
+var longDBName = Array(61).join('a');
+var longRepairPath = dbpath + Array(61).join('b') + '/';
resetDbpath( dbpath );
resetDbpath( repairpath );
-m = startMongoProgram( "mongod", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--repairpath", repairpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+var m = MongoRunner.runMongod({
+ directoryperdb: "",
+ dbpath: dbpath,
+ repairpath: repairpath,
+ noCleanData: true,
+});
db = m.getDB( baseName );
db[ baseName ].save( {} );
assert.commandWorked( db.runCommand( {repairDatabase:1, backupOriginalFiles:true} ) );
@@ -41,48 +45,97 @@ for( f in files ) {
assert( fileCount > 0, "Expected more than zero nondirectory files in the database directory" );
check();
-MongoRunner.stopMongod( port );
+MongoRunner.stopMongod( m.port );
resetDbpath( repairpath );
-m = startMongoProgram( "mongod", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+m = MongoRunner.runMongod({
+ port: m.port,
+ directoryperdb: "",
+ dbpath: dbpath,
+ noCleanData: true,
+});
db = m.getDB( baseName );
assert.commandWorked( db.runCommand( {repairDatabase:1} ) );
check();
-MongoRunner.stopMongod( port );
+MongoRunner.stopMongod( m.port );
//Test long database names
resetDbpath( repairpath );
-m = startMongoProgram( "mongod", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+m = MongoRunner.runMongod({
+ port: m.port,
+ directoryperdb: "",
+ dbpath: dbpath,
+ noCleanData: true,
+});
db = m.getDB( longDBName );
assert.writeOK(db[ baseName ].save( {} ));
assert.commandWorked( db.runCommand( {repairDatabase:1} ) );
-MongoRunner.stopMongod( port );
+MongoRunner.stopMongod( m.port );
//Test long repairPath
resetDbpath( longRepairPath )
-m = startMongoProgram( "mongod", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--repairpath", longRepairPath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+m = MongoRunner.runMongod({
+ port: m.port,
+ directoryperdb: "",
+ dbpath: dbpath,
+ repairpath: longRepairPath,
+ noCleanData: true,
+});
db = m.getDB( longDBName );
assert.commandWorked( db.runCommand( {repairDatabase:1, backupOriginalFiles: true} ) );
check();
-MongoRunner.stopMongod( port );
+MongoRunner.stopMongod( m.port );
//Test database name and repairPath with --repair
resetDbpath( longRepairPath )
-m = startMongoProgram( "mongod", "--repair", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--repairpath", longRepairPath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
-m = startMongoProgram( "mongod", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+var returnCode = runMongoProgram("mongod",
+ "--port", m.port,
+ "--repair",
+ "--directoryperdb",
+ "--dbpath", dbpath,
+ "--repairpath", longRepairPath);
+assert.eq(returnCode, 0);
+m = MongoRunner.runMongod({
+ port: m.port,
+ directoryperdb: "",
+ dbpath: dbpath,
+ noCleanData: true,
+});
db = m.getDB( longDBName );
check();
-MongoRunner.stopMongod( port );
+MongoRunner.stopMongod( m.port );
resetDbpath( repairpath );
-runMongoProgram( "mongod", "--repair", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--repairpath", repairpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
-m = startMongoProgram( "mongod", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--repairpath", repairpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+returnCode = runMongoProgram("mongod",
+ "--port", m.port,
+ "--repair",
+ "--directoryperdb",
+ "--dbpath", dbpath,
+ "--repairpath", repairpath);
+assert.eq(returnCode, 0);
+m = MongoRunner.runMongod({
+ port: m.port,
+ directoryperdb: "",
+ dbpath: dbpath,
+ repairpath: repairpath,
+ noCleanData: true,
+});
db = m.getDB( baseName );
check();
-MongoRunner.stopMongod( port );
+MongoRunner.stopMongod( m.port );
resetDbpath( repairpath );
-runMongoProgram( "mongod", "--repair", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
-m = startMongoProgram( "mongod", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+returnCode = runMongoProgram("mongod",
+ "--port", m.port,
+ "--repair",
+ "--directoryperdb",
+ "--dbpath", dbpath);
+assert.eq(returnCode, 0);
+m = MongoRunner.runMongod({
+ port: m.port,
+ directoryperdb: "",
+ dbpath: dbpath,
+ noCleanData: true,
+});
db = m.getDB( baseName );
check();
diff --git a/jstests/disk/repair3.js b/jstests/disk/repair3.js
index 6b4997cc83c..12c5356a2d6 100644
--- a/jstests/disk/repair3.js
+++ b/jstests/disk/repair3.js
@@ -17,15 +17,19 @@ if ( !doIt ) {
doIt = false;
}
-if ( doIt ) {
-
- port = allocatePorts( 1 )[ 0 ];
- dbpath = MongoRunner.dataPath + baseName + "/";
+if (doIt) {
+ var dbpath = MongoRunner.dataPath + baseName + "/";
resetDbpath( dbpath );
resetDbpath( repairpath );
- m = startMongoProgram( "mongod", "--nssize", "8", "--noprealloc", "--smallfiles", "--port", port, "--dbpath", dbpath, "--repairpath", repairpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+ var m = MongoRunner.runMongod({
+ nssize: 8,
+ noprealloc: "",
+ smallfiles: "",
+ dbpath: dbpath,
+ repairpath: repairpath,
+ });
db = m.getDB( baseName );
db[ baseName ].save( {} );
assert.commandWorked( db.runCommand( {repairDatabase:1, backupOriginalFiles:false} ) );
@@ -39,14 +43,21 @@ if ( doIt ) {
}
check();
- MongoRunner.stopMongod( port );
+ MongoRunner.stopMongod( m.port );
resetDbpath( repairpath );
- rc = runMongoProgram( "mongod", "--nssize", "8", "--noprealloc", "--smallfiles", "--repair", "--port", port, "--dbpath", dbpath, "--repairpath", repairpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+ var rc = runMongoProgram("mongod", "--nssize", "8", "--noprealloc", "--smallfiles", "--repair",
+ "--port", m.port, "--dbpath", dbpath, "--repairpath", repairpath);
assert.eq.automsg( "0", "rc" );
- m = startMongoProgram( "mongod", "--nssize", "8", "--noprealloc", "--smallfiles", "--port", port, "--dbpath", dbpath, "--repairpath", repairpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+ m = MongoRunner.runMongod({
+ nssize: 8,
+ noprealloc: "",
+ smallfiles: "",
+ port: m.port,
+ dbpath: dbpath,
+ repairpath: repairpath,
+ });
db = m.getDB( baseName );
check();
- MongoRunner.stopMongod( port );
-
-} \ No newline at end of file
+ MongoRunner.stopMongod( m.port );
+}
diff --git a/jstests/disk/repair4.js b/jstests/disk/repair4.js
index 944a4f6fd11..38049ee1f9b 100644
--- a/jstests/disk/repair4.js
+++ b/jstests/disk/repair4.js
@@ -18,14 +18,21 @@ if ( !doIt ) {
}
if ( doIt ) {
+ var repairpath = MongoRunner.dataPath + baseName + "/";
- port = allocatePorts( 1 )[ 0 ];
- repairpath = MongoRunner.dataPath + baseName + "/";
-
resetDbpath( smallpath );
resetDbpath( repairpath );
- m = startMongoProgram( "mongod", "--nssize", "8", "--noprealloc", "--smallfiles", "--port", port, "--dbpath", smallpath, "--repairpath", repairpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+ var m = MongoRunner.runMongod({
+ nssize: "8",
+ noprealloc: "",
+ smallfiles: "",
+ dbpath: smallpath,
+ repairpath: repairpath,
+ nohttpinterface: "",
+ bind_ip: "127.0.0.1",
+ });
+
db = m.getDB( baseName );
db[ baseName ].save( {} );
assert.commandWorked( db.runCommand( {repairDatabase:1, backupOriginalFiles:true} ) );
@@ -41,4 +48,4 @@ if ( doIt ) {
check();
MongoRunner.stopMongod( port );
-} \ No newline at end of file
+}
diff --git a/jstests/dur/checksum.js b/jstests/dur/checksum.js
index 2ee387261a8..ac932ab08fe 100644
--- a/jstests/dur/checksum.js
+++ b/jstests/dur/checksum.js
@@ -75,7 +75,7 @@ copyFile("jstests/libs/dur_checksum_bad_first.journal", path + "/journal/j._0");
copyFile("jstests/libs/dur_checksum_good.journal", path + "/journal/j._1");
exitCode = runMongoProgram("mongod",
- "--port", 30001,
+ "--port", allocatePort(),
"--dbpath", path,
"--journal",
"--smallfiles",
diff --git a/jstests/dur/dropdb.js b/jstests/dur/dropdb.js
index 56a4a3608f1..8c847c3a0aa 100644
--- a/jstests/dur/dropdb.js
+++ b/jstests/dur/dropdb.js
@@ -143,7 +143,7 @@ conn = MongoRunner.runMongod({restart: true,
log("verify after recovery");
verify();
-log("stop mongod 30002");
+log("stop mongod");
MongoRunner.stopMongod(conn);
sleep(5000);
diff --git a/jstests/dur/dur_jscore_passthrough.js b/jstests/dur/dur_jscore_passthrough.js
index 99a2ea7fb89..354cb76a132 100644
--- a/jstests/dur/dur_jscore_passthrough.js
+++ b/jstests/dur/dur_jscore_passthrough.js
@@ -2,9 +2,6 @@
// simple runner to run toplevel tests in jstests
//
-//TODO(mathias) add --master or make another test
-//conn = startMongodEmpty("--port", 30200, "--dbpath", MongoRunner.dataDir + "/dur_passthrough", "--dur", "--smallfiles", "--durOptions", "24");
-
var conn = MongoRunner.runMongod({journal: "", nopreallocj: "", smallfiles: "", journalOptions: 8});
db = conn.getDB("test");
conn.forceWriteMode("commands");
diff --git a/jstests/fail_point/fail_point.js b/jstests/fail_point/fail_point.js
index 42e7b1ebd9c..7a3ba663c0e 100644
--- a/jstests/fail_point/fail_point.js
+++ b/jstests/fail_point/fail_point.js
@@ -59,7 +59,7 @@ var runTest = function(adminDB) {
expectedFPState(adminDB.runCommand({ configureFailPoint: 'dummy' }), 1, { x: 1 });
};
-var conn = MongoRunner.runMongod({ port: 29000 });
+var conn = MongoRunner.runMongod();
runTest(conn.getDB('admin'));
MongoRunner.stopMongod(conn.port);
diff --git a/jstests/gle/get_last_error.js b/jstests/gle/get_last_error.js
index 2cd9836350e..5db97283d37 100644
--- a/jstests/gle/get_last_error.js
+++ b/jstests/gle/get_last_error.js
@@ -85,13 +85,12 @@ assert.eq(gle.wtimeout, null);
replTest.stopSet();
-// Next check that it still works on a lone mongod
+// Next check that it still works on a standalone mongod.
// Need to start a single server manually to keep this test in the jstests/replsets test suite
-var port = allocatePorts(1)[0];
var baseName = "SERVER-9005";
-var mongod = MongoRunner.runMongod({port: port});
-var sdb = new Mongo("localhost:"+port).getDB("test");
+var mongod = MongoRunner.runMongod({});
+var sdb = mongod.getDB("test");
sdb.foo.drop();
sdb.foo.insert({ _id: "1" });
diff --git a/jstests/libs/slow_weekly_util.js b/jstests/libs/slow_weekly_util.js
index 18fc0874daa..69b8fb27624 100644
--- a/jstests/libs/slow_weekly_util.js
+++ b/jstests/libs/slow_weekly_util.js
@@ -1,11 +1,10 @@
SlowWeeklyMongod = function( name ) {
this.name = name;
- this.port = 30201;
-
this.start = new Date();
- this.conn = MongoRunner.runMongod({port: this.port, smallfiles: "", nojournal: ""});
+ this.conn = MongoRunner.runMongod({smallfiles: "", nojournal: ""});
+ this.port = this.conn.port;
};
SlowWeeklyMongod.prototype.getDB = function( name ) {
diff --git a/jstests/libs/ssl_test.js b/jstests/libs/ssl_test.js
index cfb899ab3d0..59380776bf8 100644
--- a/jstests/libs/ssl_test.js
+++ b/jstests/libs/ssl_test.js
@@ -36,14 +36,11 @@ function SSLTest(serverOpts, clientOpts) {
return canonical;
};
- this.port = allocatePorts(1)[0];
this.serverOpts = MongoRunner.mongodOptions(canonicalServerOpts(serverOpts));
+ this.port = this.serverOpts.port;
resetDbpath(this.serverOpts.dbpath);
this.clientOpts = Object.extend({}, clientOpts || this.defaultSSLClientOptions);
-
- // Add our allocated port to the options objects.
- this.serverOpts.port = this.port;
this.clientOpts.port = this.port;
}
diff --git a/jstests/noPassthrough/dir_per_db_and_split.js b/jstests/noPassthrough/dir_per_db_and_split.js
index 8047ec9fda2..b402e0375f1 100644
--- a/jstests/noPassthrough/dir_per_db_and_split.js
+++ b/jstests/noPassthrough/dir_per_db_and_split.js
@@ -1,13 +1,10 @@
-
if (!jsTest.options().storageEngine || jsTest.options().storageEngine === "wiredTiger") {
var baseDir = "jstests_per_db_and_split_c_and_i";
- port = allocatePorts( 1 )[ 0 ];
- dbpath = MongoRunner.dataPath + baseDir + "/";
+ var dbpath = MongoRunner.dataPath + baseDir + "/";
var m = MongoRunner.runMongod({
dbpath: dbpath,
- port: port,
wiredTigerDirectoryForIndexes: '',
directoryperdb: ''});
db = m.getDB( "foo" );
@@ -19,22 +16,22 @@ if (!jsTest.options().storageEngine || jsTest.options().storageEngine === "wired
assert( listFiles( dbpath + "/foo/index" ).length > 0 );
assert( listFiles( dbpath + "/foo/collection" ).length > 0 );
- MongoRunner.stopMongod(port);
+ MongoRunner.stopMongod(m.port);
// Subsequent attempts to start server using same dbpath but different
// wiredTigerDirectoryForIndexes and directoryperdb options should fail.
assert.isnull(MongoRunner.runMongod({
dbpath: dbpath,
- port: port,
+ port: m.port,
restart: true}));
assert.isnull(MongoRunner.runMongod({
dbpath: dbpath,
- port: port,
+ port: m.port,
restart: true,
directoryperdb: ''}));
assert.isnull(MongoRunner.runMongod({
dbpath: dbpath,
- port: port,
+ port: m.port,
restart: true,
wiredTigerDirectoryForIndexes: ''}));
}
diff --git a/jstests/noPassthrough/directoryperdb.js b/jstests/noPassthrough/directoryperdb.js
index 6e2522d62a2..2421dc23172 100644
--- a/jstests/noPassthrough/directoryperdb.js
+++ b/jstests/noPassthrough/directoryperdb.js
@@ -1,7 +1,7 @@
(function() {
'use strict';
+
var baseDir = "jstests_directoryperdb";
- var port = allocatePorts( 1 )[ 0 ];
var dbpath = MongoRunner.dataPath + baseDir + "/";
var isDirectoryPerDBSupported =
@@ -11,7 +11,6 @@
var m = MongoRunner.runMongod({
dbpath: dbpath,
- port: port,
directoryperdb: ''});
if (!isDirectoryPerDBSupported) {
@@ -37,11 +36,10 @@
files = listFiles( files[0].name );
assert( files.length > 0 );
- MongoRunner.stopMongod(port);
+ MongoRunner.stopMongod(m.port);
// Subsequent attempt to start server using same dbpath without directoryperdb should fail.
assert.isnull(MongoRunner.runMongod({
dbpath: dbpath,
- port: port,
restart: true}));
}());
diff --git a/jstests/noPassthrough/split_collections_and_indexes.js b/jstests/noPassthrough/split_collections_and_indexes.js
index 73d2eede111..991a5fe2937 100644
--- a/jstests/noPassthrough/split_collections_and_indexes.js
+++ b/jstests/noPassthrough/split_collections_and_indexes.js
@@ -1,13 +1,10 @@
-
if (!jsTest.options().storageEngine || jsTest.options().storageEngine === "wiredTiger") {
-
var baseDir = "jstests_split_c_and_i";
- port = allocatePorts( 1 )[ 0 ];
- dbpath = MongoRunner.dataPath + baseDir + "/";
+
+ var dbpath = MongoRunner.dataPath + baseDir + "/";
var m = MongoRunner.runMongod({
dbpath: dbpath,
- port: port,
wiredTigerDirectoryForIndexes: ''});
db = m.getDB( "foo" );
db.bar.insert( { x : 1 } );
@@ -18,22 +15,19 @@ if (!jsTest.options().storageEngine || jsTest.options().storageEngine === "wired
assert( listFiles( dbpath + "/index" ).length > 0 );
assert( listFiles( dbpath + "/collection" ).length > 0 );
- MongoRunner.stopMongod(port);
+ MongoRunner.stopMongod(m.port);
// Subsequent attempts to start server using same dbpath but different
// wiredTigerDirectoryForIndexes and directoryperdb options should fail.
assert.isnull(MongoRunner.runMongod({
dbpath: dbpath,
- port: port,
restart: true}));
assert.isnull(MongoRunner.runMongod({
dbpath: dbpath,
- port: port,
restart: true,
directoryperdb: ''}));
assert.isnull(MongoRunner.runMongod({
dbpath: dbpath,
- port: port,
restart: true,
wiredTigerDirectoryForIndexes: '',
directoryperdb: ''}));
diff --git a/jstests/noPassthrough/ttl_capped.js b/jstests/noPassthrough/ttl_capped.js
index f3ca9cb15a7..f245056e05d 100644
--- a/jstests/noPassthrough/ttl_capped.js
+++ b/jstests/noPassthrough/ttl_capped.js
@@ -6,13 +6,12 @@
*/
(function() {
"use strict";
+
var baseDir = "jstests_ttl_capped";
- var port = allocatePorts( 1 )[ 0 ];
var dbpath = MongoRunner.dataPath + baseDir + "/";
var m = MongoRunner.runMongod({
dbpath: dbpath,
- port: port,
setParameter:"ttlMonitorSleepSecs=1"});
var db = m.getDB( "test" );
@@ -49,5 +48,5 @@
assert.eq(t.count(), 1);
assert.eq(ac.count(), 0);
- MongoRunner.stopMongod(port);
-})(); \ No newline at end of file
+ MongoRunner.stopMongod(m.port);
+})();
diff --git a/jstests/noPassthrough/wt_nojournal_fsync.js b/jstests/noPassthrough/wt_nojournal_fsync.js
index 46a881de16d..1e2f84b7e36 100644
--- a/jstests/noPassthrough/wt_nojournal_fsync.js
+++ b/jstests/noPassthrough/wt_nojournal_fsync.js
@@ -23,6 +23,7 @@ function writeDataAndRestart(doFsync) {
jsTestLog("restart node");
conn = MongoRunner.runMongod({restart: true,
+ port: conn.port,
cleanData: false,
storageEngine: "wiredTiger",
nojournal: ""});
diff --git a/jstests/noPassthroughWithMongod/httpinterface.js b/jstests/noPassthroughWithMongod/httpinterface.js
index 191a185975e..d3804cc40f1 100644
--- a/jstests/noPassthroughWithMongod/httpinterface.js
+++ b/jstests/noPassthroughWithMongod/httpinterface.js
@@ -1,11 +1,10 @@
// SERVER-9137 test that the httpinterface parameter enables the web interface
-port = allocatePorts(1)[0];
-httpPort = port + 1000;
-var conn = MongoRunner.runMongod({port: port, smallfiles: ""});
+var conn = MongoRunner.runMongod({smallfiles: ""});
+var httpPort = conn.port + 1000;
tryHttp = function() {
try {
- var mongo = new Mongo('localhost:'+httpPort) ;
+ var mongo = new Mongo('localhost:' + httpPort) ;
}
catch (e) {
return false;
@@ -18,7 +17,7 @@ assert.throws(function() {assert.soon(tryHttp, "tryHttp failed, like we expected
MongoRunner.stopMongod(conn);
-conn = MongoRunner.runMongod({ port:port, smallfiles: "", httpinterface: ""});
+conn = MongoRunner.runMongod({port: conn.port, smallfiles: "", httpinterface: ""});
assert.soon(tryHttp,
"the web interface should be running on " + httpPort);
diff --git a/jstests/noPassthroughWithMongod/index_no_retry.js b/jstests/noPassthroughWithMongod/index_no_retry.js
index 0264f308f16..7f7c39a235f 100644
--- a/jstests/noPassthroughWithMongod/index_no_retry.js
+++ b/jstests/noPassthroughWithMongod/index_no_retry.js
@@ -3,10 +3,9 @@
'use strict';
var baseName = 'index_retry';
var dbpath = MongoRunner.dataPath + baseName;
- var ports = allocatePorts(1);
+
var conn = MongoRunner.runMongod({
dbpath: dbpath,
- port: ports[0],
journal: ''});
var test = conn.getDB("test");
@@ -64,7 +63,7 @@
function abortDuringIndexBuild(options) {
var createIdx = startParallelShell(
'db.' + name + '.createIndex({ a: 1 }, { background: true });',
- ports[0]);
+ conn.port);
// Wait for the index build to start.
var times = 0;
@@ -75,7 +74,7 @@
);
print("killing the mongod");
- MongoRunner.stopMongod(ports[0], /* signal */ 9);
+ MongoRunner.stopMongod(conn.port, /* signal */ 9);
var exitCode = createIdx({checkExitSuccess: false});
assert.neq(0, exitCode, "expected shell to exit abnormally due to mongod being terminated");
@@ -85,7 +84,6 @@
conn = MongoRunner.runMongod({
dbpath: dbpath,
- port: ports[0],
journal: '',
noIndexBuildRetry: '',
restart: true});
@@ -101,6 +99,6 @@
print("Index rebuilding disabled successfully");
- MongoRunner.stopMongod(ports[0]);
+ MongoRunner.stopMongod(conn.port);
print("SUCCESS!");
}());
diff --git a/jstests/noPassthroughWithMongod/index_retry.js b/jstests/noPassthroughWithMongod/index_retry.js
index cf26b780008..806c334e151 100644
--- a/jstests/noPassthroughWithMongod/index_retry.js
+++ b/jstests/noPassthroughWithMongod/index_retry.js
@@ -3,10 +3,9 @@
'use strict';
var baseName = 'index_retry';
var dbpath = MongoRunner.dataPath + baseName;
- var ports = allocatePorts(1);
+
var conn = MongoRunner.runMongod({
dbpath: dbpath,
- port: ports[0],
journal: ''});
var test = conn.getDB("test");
@@ -64,7 +63,7 @@
function abortDuringIndexBuild(options) {
var createIdx = startParallelShell(
'db.' + name + '.createIndex({ a: 1 }, { background: true });',
- ports[0]);
+ conn.port);
// Wait for the index build to start.
var times = 0;
@@ -75,7 +74,7 @@
);
print("killing the mongod");
- MongoRunner.stopMongod(ports[0], /* signal */ 9);
+ MongoRunner.stopMongod(conn.port, /* signal */ 9);
var exitCode = createIdx({checkExitSuccess: false});
assert.neq(0, exitCode, "expected shell to exit abnormally due to mongod being terminated");
@@ -85,7 +84,6 @@
conn = MongoRunner.runMongod({
dbpath: dbpath,
- port: ports[0],
journal: '',
restart: true});
test = conn.getDB("test");
@@ -100,6 +98,6 @@
print("Index built");
- MongoRunner.stopMongod(ports[0]);
+ MongoRunner.stopMongod(conn.port);
print("SUCCESS!");
}());
diff --git a/jstests/noPassthroughWithMongod/ipv6_connection_string_validation.js b/jstests/noPassthroughWithMongod/ipv6_connection_string_validation.js
index c4896e56406..9f544248ef1 100644
--- a/jstests/noPassthroughWithMongod/ipv6_connection_string_validation.js
+++ b/jstests/noPassthroughWithMongod/ipv6_connection_string_validation.js
@@ -6,28 +6,26 @@
// and a command line to run the test in inner_mode. The inner mode test is the actual test.
if ("undefined" == typeof inner_mode) {
-
// Start a mongod with --ipv6
- port = allocatePorts( 1 )[ 0 ];
jsTest.log("Outer mode test starting mongod with --ipv6");
// NOTE: bind_ip arg is present to test if it can parse ipv6 addresses (::1 in this case).
// Unfortunately, having bind_ip = ::1 won't work in the test framework (But does work when
// tested manually), so 127.0.0.1 is also present so the test mongo shell can connect
// with that address.
- var mongod = MongoRunner.runMongod({port: port, ipv6: "", bind_ip: "::1,127.0.0.1"});
+ var mongod = MongoRunner.runMongod({ipv6: "", bind_ip: "::1,127.0.0.1"});
var args = ["mongo",
"--nodb",
"--ipv6",
"--host", "::1",
- "--port", port,
- "--eval", "inner_mode=true;port=" + port + ";",
+ "--port", mongod.port,
+ "--eval", "inner_mode=true;port=" + mongod.port + ";",
"jstests/noPassthroughWithMongod/ipv6_connection_string_validation.js" ];
var exitCode = _runMongoProgram.apply(null, args);
jsTest.log("Inner mode test finished, exit code was " + exitCode);
// Stop the server we started
jsTest.log("Outer mode test stopping server");
- MongoRunner.stopMongod(port, 15);
+ MongoRunner.stopMongod(mongod.port, 15);
// Pass the inner test's exit code back as the outer test's exit code
quit(exitCode);
diff --git a/jstests/noPassthroughWithMongod/server7428.js b/jstests/noPassthroughWithMongod/server7428.js
index ed62e7adbf6..1c6c2997804 100644
--- a/jstests/noPassthroughWithMongod/server7428.js
+++ b/jstests/noPassthroughWithMongod/server7428.js
@@ -6,15 +6,17 @@
// Verify that the copyDatabase command works appropriately when the
// target mongo instance has authentication enabled.
+(function() {
// Setup fromDb with no auth
-var fromDb = MongoRunner.runMongod({ port: 29000 });
-
+var fromDb = MongoRunner.runMongod();
+
// Setup toDb with auth
-var toDb = MongoRunner.runMongod({auth : "", port : 31001});
+var toDb = MongoRunner.runMongod({auth: ""});
var admin = toDb.getDB("admin");
admin.createUser({user: "foo", pwd: "bar", roles: jsTest.adminUserRoles});
admin.auth("foo","bar");
-
+
admin.copyDatabase('test', 'test', fromDb.host)
+})();
diff --git a/jstests/noPassthroughWithMongod/sharding_rs_arb1.js b/jstests/noPassthroughWithMongod/sharding_rs_arb1.js
index 4470a82ee88..4c36ff4f05d 100644
--- a/jstests/noPassthroughWithMongod/sharding_rs_arb1.js
+++ b/jstests/noPassthroughWithMongod/sharding_rs_arb1.js
@@ -1,5 +1,5 @@
var name = "sharding_rs_arb1"
-var replTest = new ReplSetTest( { name : name , nodes : 3 , startPort : 31000 } );
+var replTest = new ReplSetTest( { name : name , nodes : 3 } );
replTest.startSet();
var port = replTest.ports;
replTest.initiate({_id : name, members :
@@ -25,4 +25,3 @@ assert( res.ok , tojson(res) )
st.stop();
replTest.stopSet();
-
diff --git a/jstests/noPassthroughWithMongod/unix_socket1.js b/jstests/noPassthroughWithMongod/unix_socket1.js
index 8e28715558c..1b607063923 100644
--- a/jstests/noPassthroughWithMongod/unix_socket1.js
+++ b/jstests/noPassthroughWithMongod/unix_socket1.js
@@ -22,15 +22,14 @@ if ( ! _isWindows() ) {
sockdb = sock.getDB(db.getName())
assert( sockdb.runCommand('ping').ok );
- // test unix socket path
- var ports = allocatePorts(1);
+ // Test unix socket path
var path = MongoRunner.dataDir + "/sockpath";
mkdir(path);
var dataPath = MongoRunner.dataDir + "/sockpath_data";
- var conn = MongoRunner.runMongod({port: ports[0], dbpath: dataPath, unixSocketPrefix: path});
+ var conn = MongoRunner.runMongod({dbpath: dataPath, unixSocketPrefix: path});
- var sock2 = new Mongo(path+"/mongodb-"+ports[0]+".sock");
+ var sock2 = new Mongo(path + "/mongodb-" + conn.port + ".sock");
sockdb2 = sock2.getDB(db.getName())
assert( sockdb2.runCommand('ping').ok );
diff --git a/jstests/replsets/initial_sync3.js b/jstests/replsets/initial_sync3.js
index 200e0a30213..dc0455dd108 100644
--- a/jstests/replsets/initial_sync3.js
+++ b/jstests/replsets/initial_sync3.js
@@ -7,18 +7,18 @@
load("jstests/replsets/rslib.js");
var name = "initialsync3";
var host = getHostName();
-var port = allocatePorts(7);
print("Start set with three nodes");
var replTest = new ReplSetTest( {name: name, nodes: 3} );
var nodes = replTest.startSet();
replTest.initiate({
- _id : name,
- members : [
- {_id:0, host : host+":"+port[0], priority: 10},
- {_id:1, host : host+":"+port[1], priority: 0},
- {_id:2, host : host+":"+port[2], priority : 0, buildIndexes : false},
- ]});
+ _id: name,
+ members: [
+ {_id: 0, host: host + ":" + nodes[0].port, priority: 10},
+ {_id: 1, host: host + ":" + nodes[1].port, priority: 0},
+ {_id: 2, host: host + ":" + nodes[2].port, priority: 0, buildIndexes: false},
+ ]
+});
var master = replTest.getMaster();
diff --git a/jstests/replsets/stepdown.js b/jstests/replsets/stepdown.js
index a9c2b1060ff..38408d27d11 100644
--- a/jstests/replsets/stepdown.js
+++ b/jstests/replsets/stepdown.js
@@ -82,16 +82,16 @@ print("\nawait");
replTest.awaitSecondaryNodes(90000);
replTest.awaitReplication();
-// 31000 may have just voted for 31001, preventing it from becoming primary for the first 30 seconds
+// 'n0' may have just voted for 'n1', preventing it from becoming primary for the first 30 seconds
// of this assert.soon
assert.soon(function() {
try {
var result = master.getDB("admin").runCommand({isMaster: 1});
- return /31000$/.test(result.primary);
+ return new RegExp(":" + replTest.nodes[0].port + "$").test(result.primary);
} catch (x) {
return false;
}
-}, 'wait for 31000 to be primary', 60000);
+}, "wait for n0 to be primary", 60000);
master = replTest.getMaster();
var firstMaster = master;
diff --git a/jstests/replsets/tags.js b/jstests/replsets/tags.js
index 3053f28e180..2a1f77608a6 100644
--- a/jstests/replsets/tags.js
+++ b/jstests/replsets/tags.js
@@ -6,7 +6,7 @@ var num = 5;
var host = getHostName();
var name = "tags";
-var replTest = new ReplSetTest( {name: name, nodes: num, startPort:31000} );
+var replTest = new ReplSetTest( {name: name, nodes: num} );
var nodes = replTest.startSet();
var port = replTest.ports;
replTest.initiate({_id : name, members :
diff --git a/jstests/replsets/tags2.js b/jstests/replsets/tags2.js
index 074aa7b9dda..62ca15e82d8 100644
--- a/jstests/replsets/tags2.js
+++ b/jstests/replsets/tags2.js
@@ -1,7 +1,7 @@
// Change a write concern mode from 2 to 3 servers
var host = getHostName();
-var replTest = new ReplSetTest( {name: "rstag", nodes: 4, startPort: 31000} );
+var replTest = new ReplSetTest({ name: "rstag", nodes: 4 });
var nodes = replTest.startSet();
var ports = replTest.ports;
var conf = {_id : "rstag", version: 1, members : [
diff --git a/jstests/replsets/tags_with_reconfig.js b/jstests/replsets/tags_with_reconfig.js
index 755fd744de5..22b2404e009 100644
--- a/jstests/replsets/tags_with_reconfig.js
+++ b/jstests/replsets/tags_with_reconfig.js
@@ -6,7 +6,7 @@
// Start a replica set with 3 nodes
var host = getHostName();
-var replTest = new ReplSetTest( {name: "tags_with_reconfig", nodes: 3, startPort: 32000} );
+var replTest = new ReplSetTest({ name: "tags_with_reconfig", nodes: 3 });
var nodes = replTest.startSet();
var ports = replTest.ports;
diff --git a/jstests/sharding/addshard2.js b/jstests/sharding/addshard2.js
index e6ebac9ab5f..b582ff6ed7a 100644
--- a/jstests/sharding/addshard2.js
+++ b/jstests/sharding/addshard2.js
@@ -1,35 +1,34 @@
+// Don't start any shards, yet
+var s = new ShardingTest("add_shard2", 1, 0, 1, {useHostname : true});
-// don't start any shards, yet
-s = new ShardingTest( "add_shard2", 1, 0, 1, {useHostname : true} );
-
+// Start two new instances, which will be used for shards
var conn1 = MongoRunner.runMongod({useHostname: true});
var conn2 = MongoRunner.runMongod({useHostname: true});
-var rs1 = new ReplSetTest( { "name" : "add_shard2_rs1", nodes : 3 , startPort : 31200 } );
+var rs1 = new ReplSetTest( { "name" : "add_shard2_rs1", nodes : 3 } );
rs1.startSet();
rs1.initiate();
var master1 = rs1.getMaster();
-var rs2 = new ReplSetTest( { "name" : "add_shard2_rs2", nodes : 3 , startPort : 31203 } );
+var rs2 = new ReplSetTest( { "name" : "add_shard2_rs2", nodes : 3 } );
rs2.startSet();
rs2.initiate();
var master2 = rs2.getMaster();
// replica set with set name = 'config'
-var rs3 = new ReplSetTest({ 'name': 'config', nodes: 3, startPort: 31206 });
+var rs3 = new ReplSetTest({ 'name': 'config', nodes: 3 });
rs3.startSet();
rs3.initiate();
// replica set with set name = 'admin'
-var rs4 = new ReplSetTest({ 'name': 'admin', nodes: 3, startPort: 31209 });
+var rs4 = new ReplSetTest({ 'name': 'admin', nodes: 3 });
rs4.startSet();
rs4.initiate();
// replica set with configsvr: true should *not* be allowed to be added as a shard
-var rs5 = new ReplSetTest({ name: 'csrs',
- nodes: 3,
- startPort: 31212,
- nodeOptions: {configsvr: "", storageEngine: "wiredTiger" }});
+var rs5 = new ReplSetTest({name: 'csrs',
+ nodes: 3,
+ nodeOptions: {configsvr: "", storageEngine: "wiredTiger"}});
rs5.startSet();
var conf = rs5.getReplSetConfig();
conf.configsvr = true;
@@ -44,13 +43,16 @@ assert(shard, "shard wasn't found");
assert.eq("bar", shard._id, "shard has incorrect name");
// step 2. replica set
-assert(s.admin.runCommand({"addshard" : "add_shard2_rs1/"+getHostName()+":31200"}).ok, "failed to add shard in step 2");
+assert(s.admin.runCommand(
+ {"addshard" : "add_shard2_rs1/" + getHostName() + ":" + master1.port}).ok,
+ "failed to add shard in step 2");
shard = s.getDB("config").shards.findOne({"_id" : {"$nin" : ["shard0000", "bar"]}});
assert(shard, "shard wasn't found");
assert.eq("add_shard2_rs1", shard._id, "t2 name");
// step 3. replica set w/ name given
-assert(s.admin.runCommand({"addshard" : "add_shard2_rs2/"+getHostName()+":31203", "name" : "myshard"}).ok,
+assert(s.admin.runCommand({"addshard" : "add_shard2_rs2/" + getHostName() + ":" + master2.port,
+ "name" : "myshard"}).ok,
"failed to add shard in step 4");
shard = s.getDB("config").shards.findOne({"_id" : {"$nin" : ["shard0000", "bar", "add_shard2_rs1"]}});
assert(shard, "shard wasn't found");
@@ -66,28 +68,37 @@ assert.eq("shard0001", shard._id, "t4 name");
assert.eq(s.getDB("config").shards.count(), 5, "unexpected number of shards");
// step 5. replica set w/ a wrong host
-assert(!s.admin.runCommand({"addshard" : "add_shard2_rs2/NonExistingHost:31203"}).ok, "accepted bad hostname in step 5");
+var portWithoutHostRunning = allocatePort();
+assert(!s.admin.runCommand({
+ addshard: "add_shard2_rs2/NonExistingHost:" + portWithoutHostRunning
+ }).ok,
+ "accepted bad hostname in step 5");
// step 6. replica set w/ mixed wrong/right hosts
-assert(!s.admin.runCommand({"addshard" : "add_shard2_rs2/"+getHostName()+":31203,foo:9999"}).ok,
+assert(!s.admin.runCommand({
+ addshard: "add_shard2_rs2/" + getHostName() + ":" + master2.port +
+ ",foo:" + portWithoutHostRunning
+ }).ok,
"accepted bad hostname in step 6");
//
// SERVER-17231 Adding replica set w/ set name = 'config'
//
-var configReplURI = 'config/' + getHostName() + ':31206';
+var configReplURI = 'config/' + getHostName() + ':' + rs3.getMaster().port;
+
assert(!s.admin.runCommand({ 'addshard': configReplURI }).ok,
'accepted replica set shard with set name "config"');
// but we should be allowed to add that replica set using a different shard name
assert(s.admin.runCommand({ 'addshard': configReplURI, name: 'not_config' }).ok,
'unable to add replica set using valid replica set name');
+
shard = s.getDB('config').shards.findOne({ '_id': 'not_config' });
assert(shard, 'shard with name "not_config" not found');
//
// SERVER-17232 Try inserting into shard with name 'admin'
//
-assert(s.admin.runCommand({ 'addshard': 'admin/' + getHostName() + ':31209' }).ok,
+assert(s.admin.runCommand({ 'addshard': 'admin/' + getHostName() + ':' + rs4.getMaster().port}).ok,
'adding replica set with name "admin" should work');
var wRes = s.getDB('test').foo.insert({ x: 1 });
assert(!wRes.hasWriteError() && wRes.nInserted === 1,
@@ -101,4 +112,4 @@ rs1.stopSet();
rs2.stopSet();
rs3.stopSet();
rs4.stopSet();
-rs5.stopSet(); \ No newline at end of file
+rs5.stopSet();
diff --git a/jstests/sharding/addshard3.js b/jstests/sharding/addshard3.js
index aa5a21efa92..f8d43587fc0 100644
--- a/jstests/sharding/addshard3.js
+++ b/jstests/sharding/addshard3.js
@@ -1,9 +1,11 @@
+(function() {
-s = new ShardingTest( "add_shard3", 1 );
+var st = new ShardingTest("add_shard3", 1);
-var result = s.admin.runCommand({"addshard" : "localhost:31000"});
+var result = st.admin.runCommand({addshard: st.s.host});
printjson(result);
assert.eq(result.ok, 0, "don't add mongos as a shard");
+})();
diff --git a/jstests/sharding/addshard4.js b/jstests/sharding/addshard4.js
index ce459ac2824..885227a1d7c 100644
--- a/jstests/sharding/addshard4.js
+++ b/jstests/sharding/addshard4.js
@@ -2,7 +2,7 @@
s = new ShardingTest( "addshard4", 2 , 0 , 1 , {useHostname : true});
-r = new ReplSetTest({name : "addshard4", nodes : 3, startPort : 31100});
+var r = new ReplSetTest({name: "addshard4", nodes: 3});
r.startSet();
var config = r.getReplSetConfig();
@@ -31,7 +31,7 @@ var result = s.adminCommand({"addshard" : shardName});
printjson(result);
assert.eq(result, true);
-r = new ReplSetTest({name : "addshard42", nodes : 3, startPort : 31200});
+r = new ReplSetTest({name : "addshard42", nodes : 3});
r.startSet();
config = r.getReplSetConfig();
diff --git a/jstests/sharding/auth.js b/jstests/sharding/auth.js
index 4e519126ec1..d6d018719e5 100644
--- a/jstests/sharding/auth.js
+++ b/jstests/sharding/auth.js
@@ -1,31 +1,36 @@
-adminUser = {
+(function() {
+
+'use strict';
+
+var adminUser = {
db : "admin",
username : "foo",
password : "bar"
};
-testUser = {
+var testUser = {
db : "test",
username : "bar",
password : "baz"
};
-testUserReadOnly = {
+var testUserReadOnly = {
db : "test",
username : "sad",
password : "bat"
};
-function login(userObj , thingToUse ) {
- if ( ! thingToUse )
+function login(userObj, thingToUse) {
+ if (!thingToUse) {
thingToUse = s;
+ }
thingToUse.getDB(userObj.db).auth(userObj.username, userObj.password);
}
-function logout(userObj, thingToUse ) {
- if ( ! thingToUse )
+function logout(userObj, thingToUse) {
+ if (!thingToUse)
thingToUse = s;
s.getDB(userObj.db).runCommand({logout:1});
@@ -38,17 +43,6 @@ function getShardName(rsTest) {
return config._id+"/"+members.join(",");
}
-function setupTest() {
- var s = new ShardingTest( "auth1", 0 , 0 , 1 ,
- {
- rs: true,
- extraOptions : {"keyFile" : "jstests/libs/key1"},
- noChunkSize : true,
- enableBalancer:true
- } );
- return s;
-}
-
function runTest(s) {
print("adding user");
s.getDB(adminUser.db).createUser({user: adminUser.username,
@@ -60,15 +54,16 @@ function runTest(s) {
{ $set: { value : 1 }}, true ));
printjson(s.getDB("config").settings.find().toArray());
- print("restart mongos");
- MongoRunner.stopMongos(31000);
- var opts = { port : 31000, v : 2, configdb : s._configDB, keyFile : "jstests/libs/key1", chunkSize : 1 };
- var conn = startMongos( opts );
- s.s = s._mongos[0] = s["s0"] = conn;
+ print("restart mongos with different auth options");
+ s.restartMongos(0, { port: s.port,
+ v: 2,
+ configdb: s._configDB,
+ keyFile: "jstests/libs/key1",
+ chunkSize: 1 });
login(adminUser);
- d1 = new ReplSetTest({name : "d1", nodes : 3, startPort : 31100, useHostName : true });
+ var d1 = new ReplSetTest({name : "d1", nodes : 3, useHostName : true });
d1.startSet({keyFile : "jstests/libs/key2", verbose : 0});
d1.initiate();
@@ -99,12 +94,14 @@ function runTest(s) {
assert(thrown);
print("start rs w/correct key");
+
d1.stopSet();
d1.startSet({keyFile : "jstests/libs/key1", verbose : 0});
d1.initiate();
+
var master = d1.getMaster();
- print("adding shard w/auth "+shardName);
+ print("adding shard w/auth " + shardName);
result = s.getDB("admin").runCommand({addShard : shardName});
assert.eq(result.ok, 1, tojson(result));
@@ -125,12 +122,12 @@ function runTest(s) {
print("query try");
var e = assert.throws(function() {
- conn.getDB("foo").bar.findOne();
+ s.s.getDB("foo").bar.findOne();
});
printjson(e);
print("cmd try");
- assert.eq( 0, conn.getDB("foo").runCommand({listDatabases:1}).ok );
+ assert.eq(0, s.s.getDB("foo").runCommand({listDatabases:1}).ok);
print("insert try 1");
s.getDB("test").foo.insert({x:1});
@@ -144,7 +141,7 @@ function runTest(s) {
logout(testUser);
- d2 = new ReplSetTest({name : "d2", nodes : 3, startPort : 31200, useHostName : true });
+ var d2 = new ReplSetTest({name : "d2", nodes : 3, useHostName : true });
d2.startSet({keyFile : "jstests/libs/key1", verbose : 0});
d2.initiate();
d2.awaitSecondaryNodes();
@@ -218,7 +215,6 @@ function runTest(s) {
assert(false, "Number of docs found does not equal the number inserted. Missing docs: " + missingDocNumbers);
}
-
// We're only sure we aren't duplicating documents iff there's no balancing going on here
// This call also waits for any ongoing balancing to stop
s.stopBalancer(60000);
@@ -253,9 +249,10 @@ function runTest(s) {
login(testUser);
print( "testing map reduce" );
- /* sharded map reduce can be tricky since all components talk to each other.
- for example SERVER-4114 is triggered when 1 mongod connects to another for final reduce
- it's not properly tested here since addresses are localhost, which is more permissive */
+
+ // Sharded map reduce can be tricky since all components talk to each other. For example
+ // SERVER-4114 is triggered when 1 mongod connects to another for final reduce it's not
+ // properly tested here since addresses are localhost, which is more permissive.
var res = s.getDB("test").runCommand(
{mapreduce : "foo",
map : function() { emit(this.x, 1); },
@@ -265,18 +262,20 @@ function runTest(s) {
printjson(res);
assert.commandWorked(res);
- // check that dump doesn't get stuck with auth
- var x = runMongoProgram( "mongodump", "--host", "127.0.0.1:31000", "-d", testUser.db, "-u",
- testUser.username, "-p", testUser.password, "--authenticationMechanism",
- "SCRAM-SHA-1");
- print("result: "+x);
-
- // test read only users
+ // Check that dump doesn't get stuck with auth
+ var x = runMongoProgram("mongodump",
+ "--host", s.s.host,
+ "-d", testUser.db,
+ "-u", testUser.username,
+ "-p", testUser.password,
+ "--authenticationMechanism", "SCRAM-SHA-1");
+ print("result: " + x);
+ // Test read only users
print( "starting read only tests" );
- readOnlyS = new Mongo( s.getDB( "test" ).getMongo().host )
- readOnlyDB = readOnlyS.getDB( "test" );
+ var readOnlyS = new Mongo( s.getDB( "test" ).getMongo().host )
+ var readOnlyDB = readOnlyS.getDB( "test" );
print( " testing find that should fail" );
assert.throws( function(){ readOnlyDB.foo.findOne(); } )
@@ -296,6 +295,7 @@ function runTest(s) {
print("make sure currentOp/killOp fail");
assert.commandFailed(readOnlyDB.currentOp());
assert.commandFailed(readOnlyDB.killOp(123));
+
// fsyncUnlock doesn't work in mongos anyway, so no need check authorization for it
/*
broken because of SERVER-4156
@@ -307,20 +307,30 @@ function runTest(s) {
out:"blarg"
}));
*/
+
print( " testing logout (should succeed)" );
assert.commandWorked(readOnlyDB.runCommand({logout : 1}));
print("make sure currentOp/killOp fail again");
assert.commandFailed(readOnlyDB.currentOp());
assert.commandFailed(readOnlyDB.killOp(123));
- // fsyncUnlock doesn't work in mongos anyway, so no need check authorization for it
}
-var s = setupTest();
-if (s.getDB( "admin" ).runCommand( "buildInfo" ).bits < 64) {
- print("Skipping test on 32-bit platforms");
+var s = new ShardingTest("auth1", 0, 0, 1,
+ {
+ rs: true,
+ extraOptions: { "keyFile": "jstests/libs/key1" },
+ noChunkSize: true,
+ enableBalancer: true
+ });
+
+if (s.getDB('admin').runCommand('buildInfo').bits < 64) {
+ print('Skipping test on 32-bit platforms');
}
else {
runTest(s);
}
+
s.stop();
+
+})();
diff --git a/jstests/sharding/csrs_upgrade.js b/jstests/sharding/csrs_upgrade.js
index b8b6b0d6de2..a94cd2bf4e0 100644
--- a/jstests/sharding/csrs_upgrade.js
+++ b/jstests/sharding/csrs_upgrade.js
@@ -207,9 +207,11 @@ var st;
var sconfig = Object.extend({}, st.s0.fullOptions, /* deep */ true);
delete sconfig.port;
sconfig.configdb = csrsName + "/" + csrs[0].name;
- assertCanSplit(startMongos(sconfig), "when mongos started with --configdb=" + sconfig.configdb);
+ assertCanSplit(MongoRunner.runMongos(sconfig),
+ "when mongos started with --configdb=" + sconfig.configdb);
sconfig.configdb = st.s0.fullOptions.configdb;
- assertCanSplit(startMongos(sconfig), "when mongos started with --configdb=" + sconfig.configdb);
+ assertCanSplit(MongoRunner.runMongos(sconfig),
+ "when mongos started with --configdb=" + sconfig.configdb);
assertCanSplit(st.s0, "on mongos that drove the upgrade");
assertCanSplit(st.s1, "on mongos that was previously unaware of the upgrade");
}());
diff --git a/jstests/sharding/diffservers1.js b/jstests/sharding/diffservers1.js
index 8a7f2bac0a2..0d477147be8 100644
--- a/jstests/sharding/diffservers1.js
+++ b/jstests/sharding/diffservers1.js
@@ -1,6 +1,4 @@
-
-
-s = new ShardingTest( "diffservers1" , 2 );
+var s = new ShardingTest( "diffservers1" , 2 );
assert.eq( 2 , s.config.shards.count() , "server count wrong" );
assert.eq( 2 , s._configServers[0].getDB( "config" ).shards.count() , "where are servers!" );
@@ -14,8 +12,10 @@ test1.save( { a : 3 } );
assert( 3 , test1.count() );
assert( ! s.admin.runCommand( { addshard: "sdd$%" } ).ok , "bad hostname" );
-assert( ! s.admin.runCommand( { addshard: "127.0.0.1:43415" } ).ok , "host not up" );
-assert( ! s.admin.runCommand( { addshard: "10.0.0.1:43415" } ).ok , "allowed shard in IP when config is localhost" );
+var portWithoutHostRunning = allocatePort();
+assert(!s.admin.runCommand({addshard: "127.0.0.1:" + portWithoutHostRunning}).ok, "host not up");
+assert(!s.admin.runCommand({ addshard: "10.0.0.1:" + portWithoutHostRunning}).ok,
+ "allowed shard in IP when config is localhost" );
s.stop();
diff --git a/jstests/sharding/names.js b/jstests/sharding/names.js
index ff775184116..17e98f82b30 100644
--- a/jstests/sharding/names.js
+++ b/jstests/sharding/names.js
@@ -2,8 +2,8 @@
var st = new ShardingTest( name = "test", shards = 0, verbose = 2, mongos = 2, other = { rs : true } )
-var rsA = new ReplSetTest({ nodes : 2, name : "rsA", startPort : 28000 })
-var rsB = new ReplSetTest({ nodes : 2, name : "rsB", startPort : 28010 })
+var rsA = new ReplSetTest({ nodes : 2, name : "rsA" })
+var rsB = new ReplSetTest({ nodes : 2, name : "rsB" })
rsA.startSet()
rsB.startSet()
diff --git a/jstests/sharding/remove2.js b/jstests/sharding/remove2.js
index 48bb95e1e95..74f760050db 100644
--- a/jstests/sharding/remove2.js
+++ b/jstests/sharding/remove2.js
@@ -6,9 +6,6 @@ seedString = function(replTest) {
};
removeShard = function(st, replTest) {
-
-
-
print( "Removing shard with name: " + replTest.name );
res = st.admin.runCommand( { removeshard: replTest.name } )
printjson(res);
@@ -192,7 +189,7 @@ print( "Sleeping for 20 seconds to let the other shard's ReplicaSetMonitor time
sleep( 20000 );
-var rst2 = new ReplSetTest({name : rst1.name, nodes : 2, startPort : rst1.startPort + 1500, useHostName : true});
+var rst2 = new ReplSetTest({name : rst1.name, nodes : 2, useHostName : true});
rst2.startSet();
rst2.initiate();
rst2.awaitReplication();
diff --git a/jstests/sharding/sync_cluster_config/configdb_str.js b/jstests/sharding/sync_cluster_config/configdb_str.js
index 6cd592bbda4..e7a5985836e 100644
--- a/jstests/sharding/sync_cluster_config/configdb_str.js
+++ b/jstests/sharding/sync_cluster_config/configdb_str.js
@@ -10,12 +10,12 @@ st.stopBalancer();
var badConfStr = st.c1.name + ',' + st.c0.name + ',' + st.c2.name;
-var otherMongos = MongoRunner.runMongos({ port: 30998, configdb: badConfStr });
+var otherMongos = MongoRunner.runMongos({configdb: badConfStr});
var configDB = otherMongos.getDB('config');
var res = configDB.user.insert({ x: 1 });
assert.writeError(res);
-MongoRunner.stopMongos(30998);
+MongoRunner.stopMongos(otherMongos.port);
st.stop();
diff --git a/jstests/sharding/sync_cluster_config/rs_stepdown_and_pooling.js b/jstests/sharding/sync_cluster_config/rs_stepdown_and_pooling.js
index cd1efbbd8d6..d40cbf25e21 100644
--- a/jstests/sharding/sync_cluster_config/rs_stepdown_and_pooling.js
+++ b/jstests/sharding/sync_cluster_config/rs_stepdown_and_pooling.js
@@ -37,9 +37,7 @@ else {
conns.push(new Mongo(mongos.host));
conns[i].getCollection(coll + "").findOne();
}
-
- assert.eq(primary.port, 31100);
-
+
jsTest.log("Returning the connections back to the pool.");
for ( var i = 0; i < conns.length; i++ ) {
diff --git a/jstests/sharding/sync_cluster_config/sync7.js b/jstests/sharding/sync_cluster_config/sync7.js
index 65ac5b48d1b..33cf31bc899 100644
--- a/jstests/sharding/sync_cluster_config/sync7.js
+++ b/jstests/sharding/sync_cluster_config/sync7.js
@@ -13,7 +13,7 @@ s._configServers[1].getDB( "admin" ).runCommand( { _skewClockCommand : 1, skew :
// We need to start another mongos after skewing the clock, since the first mongos will have already
// tested the config servers (via the balancer) before we manually skewed them
-otherMongos = startMongos( { port : 30020, v : 2, configdb : s._configDB } );
+var otherMongos = MongoRunner.runMongos({v: 2, configdb: s._configDB});
// Initialize DB data
initDB = function(name) {
diff --git a/jstests/sharding/version1.js b/jstests/sharding/version1.js
index c7a8eb0d1a5..afe3f709fad 100644
--- a/jstests/sharding/version1.js
+++ b/jstests/sharding/version1.js
@@ -32,7 +32,7 @@ assert( a.runCommand({ setShardVersion: "alleyinsider.foo",
version: new Timestamp(2, 0),
authoritative: true,
shard: "shard0000",
- shardHost: "localhost:30000" }),
+ shardHost: s.s.host }),
"should have failed because version is config is 1|0" );
var epoch = s.getDB('config').chunks.findOne().lastmodEpoch;
@@ -42,7 +42,7 @@ assert.commandWorked( a.runCommand({ setShardVersion: "alleyinsider.foo",
versionEpoch: epoch,
authoritative: true,
shard: "shard0000",
- shardHost: "localhost:30000" }),
+ shardHost: s.s.host }),
"should have worked" );
assert( a.runCommand({ setShardVersion: "alleyinsider.foo",
diff --git a/jstests/sharding/version2.js b/jstests/sharding/version2.js
index f41342dcb8a..5a375f89c21 100644
--- a/jstests/sharding/version2.js
+++ b/jstests/sharding/version2.js
@@ -14,13 +14,16 @@ assert.eq( a.runCommand( { "getShardVersion" : "alleyinsider.foo" , configdb : s
assert.eq( a.runCommand( { "getShardVersion" : "alleyinsider.foo" , configdb : s._configDB } ).global.i, 0 );
var fooEpoch = s.getDB('config').chunks.findOne({ ns: 'alleyinsider.foo' }).lastmodEpoch;
-assert( a.runCommand({ setShardVersion: "alleyinsider.foo",
- configdb: s._configDB,
- authoritative: true,
- version: new Timestamp(1, 0),
- versionEpoch: fooEpoch,
- shard: "shard0000",
- shardHost: "localhost:30000" }).ok == 1 );
+assert.commandWorked(
+ a.runCommand({
+ setShardVersion: "alleyinsider.foo",
+ configdb: s._configDB,
+ authoritative: true,
+ version: new Timestamp(1, 0),
+ versionEpoch: fooEpoch,
+ shard: "shard0000",
+ shardHost: s.s.host,
+ }));
printjson( s.config.chunks.findOne() );
diff --git a/jstests/ssl/set_parameter_ssl.js b/jstests/ssl/set_parameter_ssl.js
index 801d4e15b72..98a4065b8a0 100644
--- a/jstests/ssl/set_parameter_ssl.js
+++ b/jstests/ssl/set_parameter_ssl.js
@@ -1,16 +1,15 @@
-// Test changing the --sslMode and --clusterAuthMode
-// parameters using setParameter
+// Test changing the --sslMode and --clusterAuthMode parameters using setParameter
var SERVER_CERT = "jstests/libs/server.pem"
var CA_CERT = "jstests/libs/ca.pem"
-port = allocatePorts(1)[0];
function testSSLTransition(oldMode, newMode, shouldSucceed) {
- var conn = MongoRunner.runMongod({port: port,
- sslMode: oldMode,
- sslPEMKeyFile: SERVER_CERT,
- sslCAFile: CA_CERT});
-
+ var conn = MongoRunner.runMongod({
+ sslMode: oldMode,
+ sslPEMKeyFile: SERVER_CERT,
+ sslCAFile: CA_CERT
+ });
+
var adminDB = conn.getDB("admin");
adminDB.createUser({user: "root", pwd: "pwd", roles: ['root']});
adminDB.auth("root", "pwd");
@@ -18,16 +17,17 @@ function testSSLTransition(oldMode, newMode, shouldSucceed) {
"sslMode" : newMode });
assert(res["ok"] == shouldSucceed, tojson(res));
- MongoRunner.stopMongod(port);
+ MongoRunner.stopMongod(conn.port);
}
function testAuthModeTransition(oldMode, newMode, sslMode, shouldSucceed) {
- var conn = MongoRunner.runMongod({port: port,
- sslMode: sslMode,
- sslPEMKeyFile: SERVER_CERT,
- sslCAFile: CA_CERT,
- clusterAuthMode: oldMode});
-
+ var conn = MongoRunner.runMongod({
+ sslMode: sslMode,
+ sslPEMKeyFile: SERVER_CERT,
+ sslCAFile: CA_CERT,
+ clusterAuthMode: oldMode
+ });
+
var adminDB = conn.getDB("admin");
adminDB.createUser({user: "root", pwd: "pwd", roles: ['root']});
adminDB.auth("root", "pwd");
@@ -35,7 +35,7 @@ function testAuthModeTransition(oldMode, newMode, sslMode, shouldSucceed) {
"clusterAuthMode" : newMode });
assert(res["ok"] == shouldSucceed, tojson(res));
- MongoRunner.stopMongod(port);
+ MongoRunner.stopMongod(conn.port);
}
testSSLTransition("allowSSL", "invalid", false);
diff --git a/jstests/ssl/ssl_cert_password.js b/jstests/ssl/ssl_cert_password.js
index 1c0e271be20..7e04755329a 100644
--- a/jstests/ssl/ssl_cert_password.js
+++ b/jstests/ssl/ssl_cert_password.js
@@ -2,7 +2,6 @@
// This tests that providing a proper password works and that providing no password or incorrect
// password fails. It uses both mongod and mongo to run the tests, since the mongod binary
// does not return error statuses to indicate an error.
-port = allocatePorts( 1 )[ 0 ];
var baseName = "jstests_ssl_ssl_cert_password";
var dbpath = MongoRunner.dataPath + baseName;
var external_scratch_dir = MongoRunner.dataPath + baseName + "/external/";
@@ -11,7 +10,6 @@ mkdir(external_scratch_dir);
// Password is correct
var md = MongoRunner.runMongod({nopreallocj: "",
- port: port,
dbpath: dbpath,
sslMode: "requireSSL",
sslPEMKeyFile: "jstests/libs/password_protected.pem",
@@ -21,7 +19,7 @@ var md = MongoRunner.runMongod({nopreallocj: "",
// Password incorrect; error logged is:
// error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
-var exit_code = runMongoProgram("mongo", "--port", port,
+var exit_code = runMongoProgram("mongo", "--port", md.port,
"--ssl", "--sslAllowInvalidCertificates",
"--sslPEMKeyFile", "jstests/libs/password_protected.pem",
"--sslPEMKeyPassword", "barf");
@@ -36,7 +34,7 @@ c.save({ a : 22 });
assert.eq(1, c.count(), "failed to insert document into dumprestore_ssl.foo collection");
exit_code = runMongoProgram("mongodump", "--out", external_scratch_dir,
- "--port", port,
+ "--port", md.port,
"--ssl",
"--sslPEMKeyFile", "jstests/libs/password_protected.pem",
"--sslPEMKeyPassword", "qwerty");
@@ -47,7 +45,7 @@ c.drop();
assert.eq(0, c.count(), "dumprestore_ssl.foo collection is not empty after drop");
exit_code = runMongoProgram("mongorestore", "--dir", external_scratch_dir,
- "--port", port,
+ "--port", md.port,
"--ssl",
"--sslPEMKeyFile", "jstests/libs/password_protected.pem",
"--sslPEMKeyPassword", "qwerty");
@@ -71,7 +69,7 @@ var exportimport_file = "data.json";
exit_code = runMongoProgram("mongoexport", "--out", external_scratch_dir + exportimport_file,
"-d", exportimport_ssl_dbname, "-c", "foo",
- "--port", port,
+ "--port", md.port,
"--ssl",
"--sslPEMKeyFile", "jstests/libs/password_protected.pem",
"--sslPEMKeyPassword", "qwerty");
@@ -83,7 +81,7 @@ assert.eq(0, c.count(), "afterdrop", "-d", exportimport_ssl_dbname, "-c", "foo")
exit_code = runMongoProgram("mongoimport", "--file", external_scratch_dir + exportimport_file,
"-d", exportimport_ssl_dbname, "-c", "foo",
- "--port", port,
+ "--port", md.port,
"--ssl",
"--sslPEMKeyFile", "jstests/libs/password_protected.pem",
"--sslPEMKeyPassword", "qwerty");
@@ -104,7 +102,7 @@ source_filename = 'jstests/ssl/ssl_cert_password.js'
filename = 'ssl_cert_password.js'
exit_code = runMongoProgram("mongofiles", "-d", mongofiles_ssl_dbname, "put", source_filename,
- "--port", port,
+ "--port", md.port,
"--ssl",
"--sslPEMKeyFile", "jstests/libs/password_protected.pem",
"--sslPEMKeyPassword", "qwerty");
@@ -122,7 +120,7 @@ assert.eq(md5, md5_computed, "md5 computed incorrectly by server");
exit_code = runMongoProgram("mongofiles", "-d", mongofiles_ssl_dbname, "get", source_filename,
"-l", external_scratch_dir + filename,
- "--port", port,
+ "--port", md.port,
"--ssl",
"--sslPEMKeyFile", "jstests/libs/password_protected.pem",
"--sslPEMKeyPassword", "qwerty");
@@ -134,6 +132,6 @@ assert.eq(md5, md5_stored, "hash of stored file does not match the expected valu
if (!_isWindows()) {
// Stop the server
- var exitCode = MongoRunner.stopMongod(port, 15);
+ var exitCode = MongoRunner.stopMongod(md.port, 15);
assert(exitCode == 0);
}
diff --git a/jstests/ssl/ssl_fips.js b/jstests/ssl/ssl_fips.js
index 3de4696d582..c831a040f52 100644
--- a/jstests/ssl/ssl_fips.js
+++ b/jstests/ssl/ssl_fips.js
@@ -1,14 +1,11 @@
// Test mongod start with FIPS mode enabled
-ports = allocatePorts(1);
-port1 = ports[0];
-var md = MongoRunner.runMongod({port: port1,
- sslMode: "requireSSL",
+var md = MongoRunner.runMongod({sslMode: "requireSSL",
sslPEMKeyFile: "jstests/libs/server.pem",
sslCAFile: "jstests/libs/ca.pem",
sslFIPSMode: ""});
var mongo = runMongoProgram("mongo",
- "--port", port1,
+ "--port", md.port,
"--ssl",
"--sslAllowInvalidCertificates",
"--sslPEMKeyFile", "jstests/libs/client.pem",
diff --git a/jstests/ssl/ssl_hostname_validation.js b/jstests/ssl/ssl_hostname_validation.js
index 98f99b557e2..6ec02381094 100644
--- a/jstests/ssl/ssl_hostname_validation.js
+++ b/jstests/ssl/ssl_hostname_validation.js
@@ -7,31 +7,34 @@ var SAN_CERT = "jstests/libs/localhostnameSAN.pem";
var CLIENT_CERT = "jstests/libs/client.pem"
var BAD_SAN_CERT = "jstests/libs/badSAN.pem";
-port = allocatePorts(1)[0];
-
function testCombination(certPath, allowInvalidHost, allowInvalidCert, shouldSucceed) {
- MongoRunner.runMongod({port: port,
- sslMode: "requireSSL",
- sslPEMKeyFile: certPath,
- sslCAFile: CA_CERT});
+ var mongod = MongoRunner.runMongod({sslMode: "requireSSL",
+ sslPEMKeyFile: certPath,
+ sslCAFile: CA_CERT});
var mongo;
if (allowInvalidCert) {
- mongo = runMongoProgram("mongo", "--port", port, "--ssl",
- "--sslCAFile", CA_CERT,
+ mongo = runMongoProgram("mongo",
+ "--port", mongod.port,
+ "--ssl",
+ "--sslCAFile", CA_CERT,
"--sslPEMKeyFile", CLIENT_CERT,
"--sslAllowInvalidCertificates",
"--eval", ";");
}
else if (allowInvalidHost) {
- mongo = runMongoProgram("mongo", "--port", port, "--ssl",
+ mongo = runMongoProgram("mongo",
+ "--port", mongod.port,
+ "--ssl",
"--sslCAFile", CA_CERT,
"--sslPEMKeyFile", CLIENT_CERT,
"--sslAllowInvalidHostnames",
"--eval", ";");
} else {
- mongo = runMongoProgram("mongo", "--port", port, "--ssl",
- "--sslCAFile", CA_CERT,
+ mongo = runMongoProgram("mongo",
+ "--port", mongod.port,
+ "--ssl",
+ "--sslCAFile", CA_CERT,
"--sslPEMKeyFile", CLIENT_CERT,
"--eval", ";");
}
@@ -46,7 +49,7 @@ function testCombination(certPath, allowInvalidHost, allowInvalidCert, shouldSuc
assert.eq(1, mongo, "Connection attempt succeeded when it should fail certPath: " +
certPath);
}
- MongoRunner.stopMongod(port);
+ MongoRunner.stopMongod(mongod.port);
}
// 1. Test client connections with different server certificates
diff --git a/jstests/ssl/x509_client.js b/jstests/ssl/x509_client.js
index 642c87ff289..59b5b268e63 100644
--- a/jstests/ssl/x509_client.js
+++ b/jstests/ssl/x509_client.js
@@ -20,8 +20,6 @@ var CA_CERT = "jstests/libs/ca.pem"
var CLIENT_USER = "C=US,ST=New York,L=New York City,O=MongoDB,OU=KernelUser,CN=client"
var INVALID_CLIENT_USER = "C=US,ST=New York,L=New York City,O=MongoDB,OU=KernelUser,CN=invalid"
-port = allocatePorts(1)[0];
-
function authAndTest(mongo) {
external = mongo.getDB("$external")
test = mongo.getDB("test");
@@ -53,10 +51,10 @@ var x509_options = {sslMode : "requireSSL",
sslPEMKeyFile : SERVER_CERT,
sslCAFile : CA_CERT};
-var mongo = MongoRunner.runMongod(Object.merge(x509_options, {port: port, auth: ""}));
+var mongo = MongoRunner.runMongod(Object.merge(x509_options, {auth: ""}));
authAndTest(mongo);
-MongoRunner.stopMongod(port);
+MongoRunner.stopMongod(mongo.port);
print("2. Testing x.509 auth to mongos");
diff --git a/jstests/sslSpecial/set_parameter_nossl.js b/jstests/sslSpecial/set_parameter_nossl.js
index 0b5e72dd4fb..280d47b6130 100644
--- a/jstests/sslSpecial/set_parameter_nossl.js
+++ b/jstests/sslSpecial/set_parameter_nossl.js
@@ -1,15 +1,12 @@
-// Test changing the --sslMode and --clusterAuthMode
+// Test changing the --sslMode and --clusterAuthMode
// parameters using setParameter
-port = allocatePorts(1)[0];
-
// setParameter should always fail since it
// cannot be used to transition from disabled/keyFile modes
function testTransition(newSSLMode, newClusterAuthMode) {
// If no parameters are given sslMode defaults to disabled
- var conn = MongoRunner.runMongod({port: port,
- clusterAuthMode: "keyFile"})
- var adminDB = conn.getDB("admin");
+ var conn = MongoRunner.runMongod({clusterAuthMode: "keyFile"});
+ var adminDB = conn.getDB("admin");
var res = adminDB.runCommand({ "setParameter" : 1,
"sslMode" : newSSLMode });
assert(!res["ok"]);
@@ -17,10 +14,9 @@ function testTransition(newSSLMode, newClusterAuthMode) {
var res = adminDB.runCommand({ "setParameter" : 1,
"clusterAuthMode" : newClusterAuthMode });
assert(!res["ok"]);
- MongoRunner.stopMongod(port);
+ MongoRunner.stopMongod(conn.port);
}
testTransition("allowSSL", "sendKeyFile");
testTransition("preferSSL", "sendX509");
testTransition("requireSSL", "x509");
-
diff --git a/jstests/tool/oplog_all_ops.js b/jstests/tool/oplog_all_ops.js
index 8f231cb233d..fb51f2b0b53 100644
--- a/jstests/tool/oplog_all_ops.js
+++ b/jstests/tool/oplog_all_ops.js
@@ -36,8 +36,14 @@ testColl.remove({ y: 2 });
var oplogColl = repl1Conn.getCollection('local.oplog.rs');
oplogColl.insert({ ts: new Timestamp(), op: 'n', ns: testColl.getFullName(), 'o': { x: 'noop' }});
-var repl2 = new ReplSetTest({ name: 'rs2', startPort: 31100, nodes: [{ nopreallocj: '' },
- { arbiter: true }, { arbiter: true }]});
+var repl2 = new ReplSetTest({
+ name: 'rs2',
+ nodes: [
+ {nopreallocj: ''},
+ {arbiter: true},
+ {arbiter: true}
+ ]
+});
repl2.startSet({ oplogSize: 10 });
repl2.initiate();
diff --git a/src/mongo/shell/replsetbridge.js b/src/mongo/shell/replsetbridge.js
index be0296eef76..4e71d8ace55 100644
--- a/src/mongo/shell/replsetbridge.js
+++ b/src/mongo/shell/replsetbridge.js
@@ -1,9 +1,8 @@
ReplSetBridge = function(rst, from, to, delay) {
var n = rst.nodes.length;
- var startPort = rst.startPort+n;
- this.port = (startPort+(from*n+to));
- this.host = rst.host+":"+this.port;
+ this.port = allocatePort();
+ this.host = rst.host + ":" + this.port;
this.dest = rst.host+":"+rst.ports[to];
this.delay = delay || 0;
@@ -13,6 +12,7 @@ ReplSetBridge = function(rst, from, to, delay) {
ReplSetBridge.prototype.start = function() {
var args = ["mongobridge", "--port", this.port, "--dest", this.dest, "--delay", this.delay];
print("ReplSetBridge starting: "+tojson(args));
+
this.bridge = startMongoProgram.apply( null , args );
print("ReplSetBridge started " + this.bridge);
};
diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js
index 7b0b36ea1d8..c98701ad5b1 100644
--- a/src/mongo/shell/replsettest.js
+++ b/src/mongo/shell/replsettest.js
@@ -40,55 +40,58 @@
* useSeedList {boolean}: Use the connection string format of this set
* as the replica set name (overrides the name property). Default: false
* keyFile {string}
- * shardSvr {boolean}: Default: false
- * startPort {number}: port offset to be used for each replica. Default: 31000
+ * shardSvr {boolean}: Whether this replica set serves as a shard in a cluster. Default: false.
* }
*
* Member variables:
* numNodes {number} - number of nodes
* nodes {Array.<Mongo>} - connection to replica set members
*/
-ReplSetTest = function( opts ){
+ReplSetTest = function(opts) {
this.name = opts.name || "testReplSet";
this.useHostName = opts.useHostName == undefined ? true : opts.useHostName;
this.host = this.useHostName ? (opts.host || getHostName()) : 'localhost';
this.oplogSize = opts.oplogSize || 40;
this.useSeedList = opts.useSeedList || false;
- this.ports = [];
- this.keyFile = opts.keyFile
+ this.keyFile = opts.keyFile;
this.shardSvr = opts.shardSvr || false;
- this.startPort = opts.startPort || 31000;
+ this.nodeOptions = {};
- this.nodeOptions = {}
- if( isObject( opts.nodes ) ){
- var len = 0
- for( var i in opts.nodes ){
+ if (isObject(opts.nodes )) {
+ var len = 0;
+
+ for(var i in opts.nodes) {
var options = this.nodeOptions[ "n" + len ] = Object.merge(opts.nodeOptions,
opts.nodes[i]);
if( i.startsWith( "a" ) ) options.arbiter = true;
len++
}
+
this.numNodes = len
}
- else if( Array.isArray( opts.nodes ) ){
- for( var i = 0; i < opts.nodes.length; i++ )
+ else if (Array.isArray(opts.nodes)) {
+ for(var i = 0; i < opts.nodes.length; i++) {
this.nodeOptions[ "n" + i ] = Object.merge(opts.nodeOptions, opts.nodes[i]);
+ }
+
this.numNodes = opts.nodes.length
}
else {
- for ( var i =0; i < opts.nodes; i++ )
+ for (var i = 0; i < opts.nodes; i++) {
this.nodeOptions[ "n" + i ] = opts.nodeOptions;
+ }
+
this.numNodes = opts.nodes;
}
-
- this.ports = allocatePorts( this.numNodes , this.startPort );
- this.nodes = []
+
+ this.ports = allocatePorts(this.numNodes);
+ this.nodes = [];
+
this.initLiveNodes()
-
+
Object.extend( this, ReplSetTest.Health )
Object.extend( this, ReplSetTest.State )
-
}
// List of nodes as host:port strings.
@@ -259,7 +262,6 @@ ReplSetTest.prototype.getOptions = function( n , extra , putBinaryFirst ){
}
ReplSetTest.prototype.startSet = function( options ) {
-
var nodes = [];
print( "ReplSetTest Starting Set" );
@@ -417,23 +419,18 @@ ReplSetTest.prototype.status = function( timeout ){
}
// Add a node to the test set
-ReplSetTest.prototype.add = function( config ) {
- if(this.ports.length == 0) {
- var nextPort = allocatePorts( 1, this.startPort )[0];
- }
- else {
- var nextPort = this.ports[this.ports.length-1] + 1;
- }
- print("ReplSetTest Next port: " + nextPort);
- this.ports.push(nextPort);
- printjson(this.ports);
-
- var nextId = this.nodes.length;
- printjson(this.nodes);
- print("ReplSetTest nextId:" + nextId);
- var newNode = this.start( nextId, config );
-
- return newNode;
+ReplSetTest.prototype.add = function(config) {
+ var nextPort = allocatePort();
+ print("ReplSetTest Next port: " + nextPort);
+
+ this.ports.push(nextPort);
+ printjson(this.ports);
+
+ var nextId = this.nodes.length;
+ printjson(this.nodes);
+
+ print("ReplSetTest nextId: " + nextId);
+ return this.start(nextId, config);
}
ReplSetTest.prototype.remove = function( nodeId ) {
@@ -634,10 +631,8 @@ ReplSetTest.prototype.getHashes = function( db ){
* before the server starts. Default: false.
*
*/
-ReplSetTest.prototype.start = function( n , options , restart , wait ){
-
- if( n.length ){
-
+ReplSetTest.prototype.start = function( n , options , restart , wait ) {
+ if( n.length ) {
var nodes = n
var started = []
@@ -648,7 +643,6 @@ ReplSetTest.prototype.start = function( n , options , restart , wait ){
}
return started
-
}
print( "ReplSetTest n is : " + n )
@@ -659,7 +653,6 @@ ReplSetTest.prototype.start = function( n , options , restart , wait ){
port : this.getPort( n ),
noprealloc : "",
smallfiles : "",
- rest : "",
replSet : this.useSeedList ? this.getURL() : this.name,
dbpath : "$set-$node" }
@@ -696,8 +689,8 @@ ReplSetTest.prototype.start = function( n , options , restart , wait ){
print("ReplSetTest " + (restart ? "(Re)" : "") + "Starting....");
var rval = this.nodes[n] = MongoRunner.runMongod( options )
-
- if( ! rval ) return rval
+
+ if(!rval) return rval;
// Add replica set specific attributes
this.nodes[n].nodeId = n
@@ -709,14 +702,13 @@ ReplSetTest.prototype.start = function( n , options , restart , wait ){
if( wait ) wait = 0
else wait = -1
}
-
- if( wait < 0 ) return rval
-
+
+ if( wait < 0 ) return rval;
+
// Wait for startup
this.waitForHealth( rval, this.UP, wait )
-
- return rval
-
+
+ return rval;
}
diff --git a/src/mongo/shell/servers.js b/src/mongo/shell/servers.js
index 90ad37bb223..e51c03d5656 100755
--- a/src/mongo/shell/servers.js
+++ b/src/mongo/shell/servers.js
@@ -101,7 +101,6 @@ MongoRunner = function(){}
MongoRunner.dataDir = "/data/db"
MongoRunner.dataPath = "/data/db/"
-MongoRunner.usedPortMap = {}
MongoRunner.VersionSub = function(regex, version) {
this.regex = regex;
@@ -218,16 +217,6 @@ MongoRunner.toRealDir = function( path, pathOpts ){
MongoRunner.toRealFile = MongoRunner.toRealDir
-MongoRunner.nextOpenPort = function(){
-
- var i = 0;
- while( MongoRunner.usedPortMap[ "" + ( 27000 + i ) ] ) i++;
- MongoRunner.usedPortMap[ "" + ( 27000 + i ) ] = true
-
- return 27000 + i
-
-}
-
/**
* Returns an iterator object which yields successive versions on toString(), starting from a
* random initial position, from an array of versions.
@@ -363,8 +352,7 @@ MongoRunner.arrToOpts = function( arr ){
MongoRunner.savedOptions = {}
-MongoRunner.mongoOptions = function( opts ){
-
+MongoRunner.mongoOptions = function(opts) {
// Don't remember waitForConnect
var waitForConnect = opts.waitForConnect;
delete opts.waitForConnect;
@@ -403,32 +391,35 @@ MongoRunner.mongoOptions = function( opts ){
// If we passed in restart : <conn> or runId : <conn>
if( isObject( opts.runId ) && opts.runId.runId ) opts.runId = opts.runId.runId
- if( opts.restart && opts.remember ) opts = Object.merge( MongoRunner.savedOptions[ opts.runId ], opts )
+ if (opts.restart && opts.remember) {
+ opts = Object.merge(MongoRunner.savedOptions[ opts.runId ], opts);
+ }
// Create a new runId
opts.runId = opts.runId || ObjectId()
-
- // Save the port if required
- if( ! opts.forgetPort ) opts.port = opts.port || MongoRunner.nextOpenPort()
-
- var shouldRemember = ( ! opts.restart && ! opts.noRemember ) || ( opts.restart && opts.appendOptions )
-
+
+ if (opts.forgetPort) {
+ delete opts.port;
+ }
+
// Normalize and get the binary version to use
opts.binVersion = MongoRunner.getBinVersionFor(opts.binVersion);
-
- if ( shouldRemember ){
- MongoRunner.savedOptions[ opts.runId ] = Object.merge( opts, {} )
+
+ var shouldRemember =
+ (!opts.restart && !opts.noRemember ) || (opts.restart && opts.appendOptions);
+ if (shouldRemember) {
+ MongoRunner.savedOptions[opts.runId] = Object.merge(opts, {});
}
-
+
// Default for waitForConnect is true
- opts.waitForConnect = (waitForConnect == undefined || waitForConnect == null) ?
- true : waitForConnect;
+ opts.waitForConnect =
+ (waitForConnect == undefined || waitForConnect == null) ? true : waitForConnect;
+
+ opts.port = opts.port || allocatePort();
+
+ opts.pathOpts = Object.merge(opts.pathOpts || {},
+ { port : "" + opts.port, runId : "" + opts.runId });
- opts.port = opts.port || MongoRunner.nextOpenPort()
- MongoRunner.usedPortMap[ "" + parseInt( opts.port ) ] = true
-
- opts.pathOpts = Object.merge( opts.pathOpts || {}, { port : "" + opts.port, runId : "" + opts.runId } )
-
return opts
}
@@ -509,9 +500,8 @@ MongoRunner.mongodOptions = function( opts ){
return opts
}
-MongoRunner.mongosOptions = function( opts ){
-
- opts = MongoRunner.mongoOptions( opts )
+MongoRunner.mongosOptions = function( opts ) {
+ opts = MongoRunner.mongoOptions(opts);
// Normalize configdb option to be host string if currently a host
if( opts.configdb && opts.configdb.getDB ){
@@ -611,24 +601,23 @@ MongoRunner.runMongod = function( opts ){
return mongod
}
-MongoRunner.runMongos = function( opts ){
-
+MongoRunner.runMongos = function(opts) {
opts = opts || {}
+
var useHostName = false;
var runId = null;
var waitForConnect = true;
var fullOptions = opts;
- if( isObject( opts ) ) {
-
+ if (isObject(opts)) {
opts = MongoRunner.mongosOptions( opts );
fullOptions = opts;
-
+
useHostName = opts.useHostName || opts.useHostname;
runId = opts.runId;
waitForConnect = opts.waitForConnect;
-
- opts = MongoRunner.arrOptions( "mongos", opts )
+
+ opts = MongoRunner.arrOptions("mongos", opts);
}
var mongos = MongoRunner.startWithArgs(opts, waitForConnect);
@@ -678,33 +667,11 @@ MongoRunner.stopMongod = function( port, signal, opts ){
var opts = MongoRunner.savedOptions( port )
if( opts ) port = parseInt( opts.port )
}
-
- var exitCode = _stopMongoProgram( parseInt( port ), parseInt( signal ), opts )
-
- delete MongoRunner.usedPortMap[ "" + parseInt( port ) ]
- return exitCode
+ return _stopMongoProgram(parseInt(port), parseInt(signal), opts);
}
-MongoRunner.stopMongos = MongoRunner.stopMongod
-
-MongoRunner.isStopped = function( port ){
-
- if( ! port ) {
- print( "Cannot detect if process " + port + " is stopped." )
- return
- }
-
- if( port.port )
- port = parseInt( port.port )
-
- if( port instanceof ObjectId ){
- var opts = MongoRunner.savedOptions( port )
- if( opts ) port = parseInt( opts.port )
- }
-
- return MongoRunner.usedPortMap[ "" + parseInt( port ) ] ? false : true
-}
+MongoRunner.stopMongos = MongoRunner.stopMongod;
/**
* Starts an instance of the specified mongo tool
@@ -749,19 +716,17 @@ _startMongodEmpty = function () {
return startMongoProgram.apply(null, args);
}
+
_startMongod = function () {
print("startMongod WARNING DELETES DATA DIRECTORY THIS IS FOR TESTING ONLY");
return _startMongodEmpty.apply(null, arguments);
}
+
_startMongodNoReset = function(){
var args = createMongoArgs( "mongod" , arguments );
return startMongoProgram.apply( null, args );
}
-startMongos = function(args){
- return MongoRunner.runMongos(args);
-}
-
/**
* Returns a new argArray with any test-specific arguments added.
*/
diff --git a/src/mongo/shell/servers_misc.js b/src/mongo/shell/servers_misc.js
index 778d1d2ab75..4c190586640 100644
--- a/src/mongo/shell/servers_misc.js
+++ b/src/mongo/shell/servers_misc.js
@@ -1,7 +1,7 @@
ToolTest = function( name, extraOptions ){
this.name = name;
this.options = extraOptions;
- this.port = allocatePorts(1)[0];
+ this.port = allocatePort();
this.baseName = "jstests_tool_" + name;
this.root = MongoRunner.dataPath + this.baseName;
this.dbpath = this.root + "/";
@@ -62,7 +62,7 @@ ToolTest.prototype.runTool = function(){
ReplTest = function( name, ports ){
this.name = name;
- this.ports = ports || allocatePorts( 2 );
+ this.ports = ports || allocatePorts(2);
}
ReplTest.prototype.getPort = function( master ){
@@ -162,14 +162,35 @@ ReplTest.prototype.stop = function( master , signal ){
return _stopMongoProgram( this.getPort( master ) , signal || 15 );
}
-allocatePorts = function( n , startPort ) {
- var ret = [];
- var start = startPort || 31000;
- for( var i = start; i < start + n; ++i )
- ret.push( i );
- return ret;
-}
+/**
+ * Returns a port number that has not been given out to any other caller from the same mongo shell.
+ */
+allocatePort = (function() {
+ var maxPort = Math.pow(2, 16) - 1;
+ // Chosen in an attempt to have a large number of unassigned ports that are also outside the
+ // ephemeral port range.
+ var nextPort = 20000;
+
+ return function() {
+ if (nextPort === maxPort) {
+ throw new Error("Exceeded maximum port range in allocatePort()");
+ }
+ return nextPort++;
+ };
+})();
+
+/**
+ * Returns a list of 'numPorts' port numbers that have not been given out to any other caller from
+ * the same mongo shell.
+ */
+allocatePorts = function(numPorts) {
+ var ports = [];
+ for (var i = 0; i < numPorts; i++) {
+ ports.push(allocatePort());
+ }
+ return ports;
+};
SyncCCTest = function( testName , extraMongodOptions ){
this._testName = testName;
diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js
index ae78be9a34d..1abde675fe6 100644
--- a/src/mongo/shell/shardingtest.js
+++ b/src/mongo/shell/shardingtest.js
@@ -78,8 +78,7 @@
* c0, c1, ... {Mongo} - same as config0, config1, ...
* configRS - If the config servers are a replset, this will contain the config ReplSetTest object
*/
-ShardingTest = function( testName , numShards , verboseLevel , numMongos , otherParams ){
-
+ShardingTest = function( testName , numShards , verboseLevel , numMongos , otherParams ) {
this._startTime = new Date();
// Check if testName is an object, if so, pull params from there
@@ -87,8 +86,7 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other
var numConfigs = 3;
otherParams = Object.merge( otherParams || {}, {} )
- if( isObject( testName ) ){
-
+ if( isObject( testName ) ) {
var params = Object.merge( testName, {} )
testName = params.name || "test"
@@ -160,7 +158,6 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other
true : otherParams.useHostname;
keyFile = otherParams.keyFile || otherParams.extraOptions.keyFile
-
this._testName = testName
this._otherParams = otherParams
@@ -180,6 +177,7 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other
this._rs = []
this._rsObjects = []
+ // Start the MongoD servers (shards)
for ( var i = 0; i < numShards; i++ ) {
if( otherParams.rs || otherParams["rs" + i] ){
var setName = testName + "-rs" + i;
@@ -188,63 +186,74 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other
noJournalPrealloc : otherParams.nopreallocj,
oplogSize : 40,
pathOpts : Object.merge( pathOpts, { shard : i } )}
-
+
rsDefaults = Object.merge( rsDefaults, ShardingTest.rsOptions || {} )
rsDefaults = Object.merge( rsDefaults, otherParams.rs )
rsDefaults = Object.merge( rsDefaults, otherParams.rsOptions )
rsDefaults = Object.merge( rsDefaults, otherParams["rs" + i] )
rsDefaults.nodes = rsDefaults.nodes || otherParams.numReplicas
-
+
var numReplicas = rsDefaults.nodes || 3
delete rsDefaults.nodes
-
+
print( "Replica set test!" )
-
- var rs = new ReplSetTest( { name : setName , nodes : numReplicas , startPort : 31100 + ( i * 100 ), useHostName : otherParams.useHostname, keyFile : keyFile, shardSvr : true } );
- this._rs[i] = { setName : setName , test : rs , nodes : rs.startSet( rsDefaults ) , url : rs.getURL() };
+
+ var rs = new ReplSetTest({ name : setName,
+ nodes : numReplicas,
+ useHostName : otherParams.useHostname,
+ keyFile : keyFile,
+ shardSvr : true });
+
+ this._rs[i] = { setName : setName,
+ test : rs,
+ nodes : rs.startSet(rsDefaults),
+ url : rs.getURL() };
+
rs.initiate();
this["rs" + i] = rs
-
+
this._rsObjects[i] = rs
-
+
this._alldbpaths.push( null )
this._connections.push( null )
}
else {
- var options = { useHostname : otherParams.useHostname,
- noJournalPrealloc : otherParams.nopreallocj,
- port : 30000 + i,
- pathOpts : Object.merge( pathOpts, { shard : i } ),
- dbpath : "$testName$shard",
- keyFile : keyFile
- }
-
+ var options = {
+ useHostname: otherParams.useHostname,
+ noJournalPrealloc: otherParams.nopreallocj,
+ pathOpts: Object.merge(pathOpts, {shard: i}),
+ dbpath: "$testName$shard",
+ keyFile: keyFile
+ };
+
options = Object.merge( options, ShardingTest.shardOptions || {} )
-
+
if( otherParams.shardOptions && otherParams.shardOptions.binVersion ){
- otherParams.shardOptions.binVersion =
+ otherParams.shardOptions.binVersion =
MongoRunner.versionIterator( otherParams.shardOptions.binVersion )
}
-
+
options = Object.merge( options, otherParams.shardOptions )
options = Object.merge( options, otherParams["d" + i] )
-
+
var conn = MongoRunner.runMongod( options );
-
+
this._alldbpaths.push( testName +i )
this._connections.push( conn );
this["shard" + i] = conn
this["d" + i] = conn
-
+
this._rs[i] = null
this._rsObjects[i] = null
}
}
-
+
// Do replication on replica sets if required
- for ( var i = 0; i < numShards; i++ ){
- if( ! otherParams.rs && ! otherParams["rs" + i] ) continue
-
+ for (var i = 0; i < numShards; i++) {
+ if(!otherParams.rs && !otherParams["rs" + i]) {
+ continue;
+ }
+
var rs = this._rs[i].test;
rs.getMaster().getDB( "admin" ).foo.save( { x : 1 } )
@@ -271,22 +280,20 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other
this._configServers = []
this._configServersAreRS = !otherParams.sync;
+ // Start the config servers
if (otherParams.sync) {
var configNames = [];
for ( var i = 0; i < 3 ; i++ ) {
-
var options = { useHostname : otherParams.useHostname,
noJournalPrealloc : otherParams.nopreallocj,
- port : 29000 + i,
pathOpts : Object.merge( pathOpts, { config : i } ),
dbpath : "$testName-config$config",
keyFile : keyFile,
- configsvr : ""
- }
+ configsvr : "" };
options = Object.merge( options, ShardingTest.configOptions || {} )
- if( otherParams.configOptions && otherParams.configOptions.binVersion ){
+ if (otherParams.configOptions && otherParams.configOptions.binVersion) {
otherParams.configOptions.binVersion =
MongoRunner.versionIterator( otherParams.configOptions.binVersion )
}
@@ -298,32 +305,33 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other
this._alldbpaths.push( testName + "-config" + i )
- this._configServers.push( conn );
- configNames.push( conn.name )
+ this._configServers.push(conn);
+ configNames.push(conn.name);
+
this["config" + i] = conn
this["c" + i] = conn
}
- this._configDB = configNames.join( "," );
+
+ this._configDB = configNames.join(',');
}
else {
// Using replica set for config servers
var rstOptions = { useHostName : otherParams.useHostname,
- startPort : 29000,
keyFile : keyFile,
- name: testName + "-configRS"
- };
+ name: testName + "-configRS",
+ };
// when using CSRS, always use wiredTiger as the storage engine
var startOptions = { pathOpts: pathOpts,
configsvr : "",
noJournalPrealloc : otherParams.nopreallocj,
- storageEngine : "wiredTiger"
+ storageEngine : "wiredTiger",
};
startOptions = Object.merge( startOptions, ShardingTest.configOptions || {} )
- if( otherParams.configOptions && otherParams.configOptions.binVersion ){
+ if ( otherParams.configOptions && otherParams.configOptions.binVersion ) {
otherParams.configOptions.binVersion =
MongoRunner.versionIterator( otherParams.configOptions.binVersion )
}
@@ -354,6 +362,7 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other
}
printjson("config servers: " + this._configDB);
+
var connectWithRetry = function(url) {
var conn = null;
assert.soon( function() {
@@ -381,40 +390,44 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other
}
this._mongos = []
- this._mongoses = this._mongos
- for ( var i = 0; i < ( ( numMongos == 0 ? -1 : numMongos ) || 1 ); i++ ){
-
- var options = { useHostname : otherParams.useHostname,
- port : 31000 - i - 1,
- pathOpts : Object.merge( pathOpts, { mongos : i } ),
- configdb : this._configDB,
- verbose : verboseLevel || 0,
- keyFile : keyFile
- }
- if ( ! otherParams.noChunkSize ) {
+
+ // Start the MongoS servers
+ for (var i = 0; i < ( ( numMongos == 0 ? -1 : numMongos ) || 1 ); i++ ){
+ options = {
+ useHostname: otherParams.useHostname,
+ pathOpts: Object.merge(pathOpts, {mongos: i}),
+ configdb: this._configDB,
+ verbose: verboseLevel || 0,
+ keyFile: keyFile
+ };
+
+ if (!otherParams.noChunkSize) {
options.chunkSize = otherParams.chunksize || otherParams.chunkSize || 50;
}
options = Object.merge( options, ShardingTest.mongosOptions || {} )
-
- if( otherParams.mongosOptions && otherParams.mongosOptions.binVersion ){
- otherParams.mongosOptions.binVersion =
- MongoRunner.versionIterator( otherParams.mongosOptions.binVersion )
+
+ if (otherParams.mongosOptions && otherParams.mongosOptions.binVersion) {
+ otherParams.mongosOptions.binVersion =
+ MongoRunner.versionIterator(otherParams.mongosOptions.binVersion);
}
-
+
options = Object.merge( options, otherParams.mongosOptions )
options = Object.merge( options, otherParams.extraOptions )
options = Object.merge( options, otherParams["s" + i] )
-
- var conn = MongoRunner.runMongos( options )
- this._mongos.push( conn );
- if ( i == 0 ) this.s = conn
- this["s" + i] = conn
- }
+ conn = MongoRunner.runMongos(options);
- var admin = this.admin = this.s.getDB( "admin" );
- this.config = this.s.getDB( "config" );
+ this._mongos.push(conn);
+
+ if (i === 0) {
+ this.s = conn;
+ this.admin = conn.getDB('admin');
+ this.config = conn.getDB('config');
+ }
+
+ this["s" + i] = conn;
+ }
// Disable the balancer unless it is explicitly turned on
if ( !otherParams.enableBalancer ) {
@@ -437,23 +450,30 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other
}
}
- if ( ! otherParams.manualAddShard ){
- this._shardNames = []
- var shardNames = this._shardNames
+ if (!otherParams.manualAddShard) {
+ this._shardNames = [];
+
+ var testName = this._testName;
+ var admin = this.admin;
+ var shardNames = this._shardNames;
+
this._connections.forEach(
- function(z){
+ function(z) {
var n = z.name;
- if ( ! n ){
+ if (!n){
n = z.host;
- if ( ! n )
+ if (!n) {
n = z;
+ }
}
- print( "ShardingTest " + this._testName + " going to add shard : " + n )
- x = admin.runCommand( { addshard : n } );
- printjson( x )
- assert( x.ok );
- shardNames.push( x.shardAdded )
- z.shardName = x.shardAdded
+
+ print("ShardingTest " + testName + " going to add shard : " + n);
+
+ var result = admin.runCommand({ addshard: n });
+ assert.commandWorked(result, "Failed to add shard " + n);
+
+ shardNames.push(result.shardAdded);
+ z.shardName = result.shardAdded;
}
);
}
@@ -581,30 +601,29 @@ ShardingTest.prototype.getFirstOther = function( one ){
}
ShardingTest.prototype.stop = function(){
- for ( var i=0; i<this._mongos.length; i++ ){
- _stopMongoProgram( 31000 - i - 1 );
+ for (var i = 0; i < this._mongos.length; i++) {
+ MongoRunner.stopMongos(this._mongos[i].port);
}
- for ( var i=0; i<this._connections.length; i++){
- _stopMongoProgram( 30000 + i );
- }
- if ( this._rs ){
- for ( var i=0; i<this._rs.length; i++ ){
- if( this._rs[i] ) this._rs[i].test.stopSet( 15 );
+
+ for (var i = 0; i < this._connections.length; i++) {
+ if (this._rs[i]) {
+ this._rs[i].test.stopSet(15);
+ } else {
+ MongoRunner.stopMongod(this._connections[i].port);
}
}
+
if (this._configServersAreRS) {
this.configRS.stopSet();
- }
- else {
+ } else {
// Old style config triplet
- for ( var i=0; i<this._configServers.length; i++ ){
- MongoRunner.stopMongod( this._configServers[i] )
+ for (var i = 0; i < this._configServers.length; i++) {
+ MongoRunner.stopMongod(this._configServers[i]);
}
}
- if ( this._alldbpaths ){
- for( i=0; i<this._alldbpaths.length; i++ ){
- resetDbpath( MongoRunner.dataPath + this._alldbpaths[i] );
- }
+
+ for (var i = 0; i < this._alldbpaths.length; i++) {
+ resetDbpath(MongoRunner.dataPath + this._alldbpaths[i]);
}
var timeMillis = new Date().getTime() - this._startTime.getTime();
@@ -1145,20 +1164,30 @@ ShardingTest.prototype.stopMongod = function(n) {
};
/**
- * Restarts a previously stopped mongos using the same parameters as before.
+ * Restarts a previously stopped mongos.
*
- * Warning: Overwrites the old s (if n = 0) and sn member variables.
+ * If opts is specified, the new mongos is started using those options. Otherwise, it is started
+ * with its previous parameters.
+ *
+ * Warning: Overwrites the old s (if n = 0) admin, config, and sn member variables.
*/
-ShardingTest.prototype.restartMongos = function(n) {
+ShardingTest.prototype.restartMongos = function(n, opts) {
var mongos = this['s' + n];
+
+ if (opts === undefined) {
+ opts = this['s' + n];
+ opts.restart = true;
+ }
+
MongoRunner.stopMongos(mongos);
- mongos.restart = true;
- var newConn = MongoRunner.runMongos(mongos);
+ var newConn = MongoRunner.runMongos(opts);
this['s' + n] = newConn;
if (n == 0) {
this.s = newConn;
+ this.admin = newConn.getDB('admin');
+ this.config = newConn.getDB('config');
}
};