diff options
author | Spencer T Brody <spencer@mongodb.com> | 2015-03-22 12:08:21 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2015-04-06 18:19:21 -0400 |
commit | 6ccb82c987a47995fd7d8019d7fd4d1e557478b4 (patch) | |
tree | 2542816a69e9faaaff840754b42f0229dc905ccd /jstests/tool | |
parent | 7baac52f05a3e0cbdb7168e51836f507eda99dff (diff) | |
download | mongo-6ccb82c987a47995fd7d8019d7fd4d1e557478b4.tar.gz |
SERVER-17450 Standardize on a single way to start mongod in tests
Diffstat (limited to 'jstests/tool')
-rw-r--r-- | jstests/tool/dumpauth.js | 7 | ||||
-rw-r--r-- | jstests/tool/dumprestore3.js | 7 | ||||
-rw-r--r-- | jstests/tool/dumprestore7.js | 5 | ||||
-rw-r--r-- | jstests/tool/restorewithauth.js | 19 | ||||
-rw-r--r-- | jstests/tool/stat1.js | 7 | ||||
-rw-r--r-- | jstests/tool/tool1.js | 11 |
6 files changed, 24 insertions, 32 deletions
diff --git a/jstests/tool/dumpauth.js b/jstests/tool/dumpauth.js index 7ae165f5ce1..58bbfa82e9e 100644 --- a/jstests/tool/dumpauth.js +++ b/jstests/tool/dumpauth.js @@ -1,9 +1,8 @@ // dumpauth.js // test mongodump with authentication -port = allocatePorts( 1 )[ 0 ]; baseName = "tool_dumpauth"; -m = startMongod( "--auth", "--port", port, "--dbpath", MongoRunner.dataPath + baseName, "--nohttpinterface", "--bind_ip", "127.0.0.1" ); +var m = MongoRunner.runMongod({auth: "", bind_ip: "127.0.0.1"}); db = m.getDB( "admin" ); db.createUser({user: "testuser" , pwd: "testuser", roles: jsTest.adminUserRoles}); @@ -21,7 +20,7 @@ x = runMongoProgram( "mongodump", "--authenticationDatabase=admin", "-u", "testuser", "-p", "testuser", - "-h", "127.0.0.1:"+port, + "-h", "127.0.0.1:"+m.port, "--collection", "testcol" ); assert.eq(x, 0, "mongodump should succeed with authentication"); @@ -31,7 +30,7 @@ x = runMongoProgram( "mongodump", "--authenticationDatabase=admin", "-u", "testuser", "-p", "testuser", - "-h", "127.0.0.1:"+port, + "-h", "127.0.0.1:"+m.port, "--collection", "testcol", "--out", "-" ); assert.eq(x, 0, "mongodump should succeed with authentication while using '--out'"); diff --git a/jstests/tool/dumprestore3.js b/jstests/tool/dumprestore3.js index 9fcd540a767..39f97d3992f 100644 --- a/jstests/tool/dumprestore3.js +++ b/jstests/tool/dumprestore3.js @@ -30,8 +30,7 @@ var master = replTest.getMaster(); { step("dump & restore a db into a slave"); - var port = 30020; - var conn = startMongodTest(port, name + "-other"); + var conn = MongoRunner.runMongod({}); var c = conn.getDB("foo").bar; c.save({ a: 22 }); assert.eq(1, c.count(), "setup2"); @@ -41,7 +40,7 @@ step("try mongorestore to slave"); var data = MongoRunner.dataDir + "/dumprestore3-other1/"; resetDbpath(data); -runMongoProgram( "mongodump", "--host", "127.0.0.1:"+port, "--out", data ); +runMongoProgram( "mongodump", "--host", "127.0.0.1:"+conn.port, "--out", data ); var x = runMongoProgram( "mongorestore", "--host", "127.0.0.1:"+replTest.ports[1], "--dir", data ); assert.neq(x, 0, "mongorestore should exit w/ 1 on slave"); @@ -49,7 +48,7 @@ assert.neq(x, 0, "mongorestore should exit w/ 1 on slave"); step("try mongoimport to slave"); dataFile = MongoRunner.dataDir + "/dumprestore3-other2.json"; -runMongoProgram( "mongoexport", "--host", "127.0.0.1:"+port, "--out", dataFile, "--db", "foo", "--collection", "bar" ); +runMongoProgram( "mongoexport", "--host", "127.0.0.1:"+conn.port, "--out", dataFile, "--db", "foo", "--collection", "bar" ); x = runMongoProgram( "mongoimport", "--host", "127.0.0.1:"+replTest.ports[1], "--file", dataFile ); assert.neq(x, 0, "mongoreimport should exit w/ 1 on slave"); diff --git a/jstests/tool/dumprestore7.js b/jstests/tool/dumprestore7.js index a9225dd7044..04414bf85a8 100644 --- a/jstests/tool/dumprestore7.js +++ b/jstests/tool/dumprestore7.js @@ -36,8 +36,7 @@ var master = replTest.getMaster(); } } { - var port = 30020; - var conn = startMongodTest(port, name + "-other"); + var conn = MongoRunner.runMongod({}); } step("try mongodump with $timestamp"); @@ -52,7 +51,7 @@ MongoRunner.runMongoTool( "mongodump", step("try mongorestore from $timestamp"); -runMongoProgram( "mongorestore", "--host", "127.0.0.1:"+port, "--dir", data, "--writeConcern", 1); +runMongoProgram( "mongorestore", "--host", "127.0.0.1:"+conn.port, "--dir", data, "--writeConcern", 1); var x = 9; x = conn.getDB("local").getCollection("oplog.rs").count(); diff --git a/jstests/tool/restorewithauth.js b/jstests/tool/restorewithauth.js index d17769cf396..aec3d6859bc 100644 --- a/jstests/tool/restorewithauth.js +++ b/jstests/tool/restorewithauth.js @@ -15,10 +15,8 @@ */ -var port = allocatePorts(1)[0]; baseName = "jstests_restorewithauth"; -var conn = startMongod( "--port", port, "--dbpath", MongoRunner.dataPath + baseName, "--nohttpinterface", - "--nojournal", "--bind_ip", "127.0.0.1" ); +var conn = MongoRunner.runMongod({nojournal: "", bind_ip: "127.0.0.1"}); // write to ns foo.bar var foo = conn.getDB( "foo" ); @@ -42,17 +40,16 @@ assert.eq(foo.baz.getIndexes().length, 1); // get data dump var dumpdir = MongoRunner.dataDir + "/restorewithauth-dump1/"; resetDbpath( dumpdir ); -x = runMongoProgram("mongodump", "--db", "foo", "-h", "127.0.0.1:"+port, "--out", dumpdir); +x = runMongoProgram("mongodump", "--db", "foo", "-h", "127.0.0.1:"+ conn.port, "--out", dumpdir); // now drop the db foo.dropDatabase(); // stop mongod -stopMongod( port ); +MongoRunner.stopMongod(conn); // start mongod with --auth -conn = startMongod( "--auth", "--port", port, "--dbpath", MongoRunner.dataPath + baseName, "--nohttpinterface", - "--nojournal", "--bind_ip", "127.0.0.1" ); +conn = MongoRunner.runMongod({auth: "", nojournal: "", bind_ip: "127.0.0.1"}); // admin user var admin = conn.getDB( "admin" ) @@ -67,7 +64,7 @@ assert.eq(-1, collNames.indexOf("bar"), "bar collection already exists"); assert.eq(-1, collNames.indexOf("baz"), "baz collection already exists"); // now try to restore dump -x = runMongoProgram( "mongorestore", "-h", "127.0.0.1:" + port, "--dir" , dumpdir, "-vvvvv" ); +x = runMongoProgram( "mongorestore", "-h", "127.0.0.1:" + conn.port, "--dir" , dumpdir, "-vvvvv" ); // make sure that the collection isn't restored collNames = foo.getCollectionNames(); @@ -76,7 +73,7 @@ assert.eq(-1, collNames.indexOf("baz"), "baz collection was restored"); // now try to restore dump with correct credentials x = runMongoProgram( "mongorestore", - "-h", "127.0.0.1:" + port, + "-h", "127.0.0.1:" + conn.port, "-d", "foo", "--authenticationDatabase=admin", "-u", "admin", @@ -99,7 +96,7 @@ foo.createUser({user: 'user', pwd: 'password', roles: jsTest.basicUserRoles}); // now try to restore dump with foo database credentials x = runMongoProgram("mongorestore", - "-h", "127.0.0.1:" + port, + "-h", "127.0.0.1:" + conn.port, "-d", "foo", "-u", "user", "-p", "password", @@ -114,4 +111,4 @@ assert.eq(foo.bar.count(), 4); assert.eq(foo.baz.count(), 4); assert.eq(foo.bar.getIndexes().length + foo.baz.getIndexes().length, 3); // _id on foo, _id on bar, x on foo -stopMongod( port ); +MongoRunner.stopMongod(conn); diff --git a/jstests/tool/stat1.js b/jstests/tool/stat1.js index 71ec776c170..0b5bf7f02b0 100644 --- a/jstests/tool/stat1.js +++ b/jstests/tool/stat1.js @@ -1,16 +1,15 @@ // stat1.js // test mongostat with authentication SERVER-3875 -port = allocatePorts( 1 )[ 0 ]; baseName = "tool_stat1"; -m = startMongod( "--auth", "--port", port, "--dbpath", MongoRunner.dataPath + baseName, "--nohttpinterface", "--bind_ip", "127.0.0.1" ); +var m = MongoRunner.runMongod({auth: "", bind_ip: "127.0.0.1"}); db = m.getDB( "admin" ); db.createUser({user: "eliot" , pwd: "eliot", roles: jsTest.adminUserRoles}); assert( db.auth( "eliot" , "eliot" ) , "auth failed" ); -x = runMongoProgram( "mongostat", "--host", "127.0.0.1:"+port, "--username", "eliot", "--password", "eliot", "--rowcount", "1", "--authenticationDatabase", "admin" ); +x = runMongoProgram( "mongostat", "--host", "127.0.0.1:"+m.port, "--username", "eliot", "--password", "eliot", "--rowcount", "1", "--authenticationDatabase", "admin" ); assert.eq(x, 0, "mongostat should exit successfully with eliot:eliot"); -x = runMongoProgram( "mongostat", "--host", "127.0.0.1:"+port, "--username", "eliot", "--password", "wrong", "--rowcount", "1", "--authenticationDatabase", "admin" ); +x = runMongoProgram( "mongostat", "--host", "127.0.0.1:"+m.port, "--username", "eliot", "--password", "wrong", "--rowcount", "1", "--authenticationDatabase", "admin" ); assert.neq(x, 0, "mongostat should exit with -1 with eliot:wrong"); diff --git a/jstests/tool/tool1.js b/jstests/tool/tool1.js index 5bd191faa49..6fb0a1f0f02 100644 --- a/jstests/tool/tool1.js +++ b/jstests/tool/tool1.js @@ -16,17 +16,16 @@ function fileSize(){ } -port = allocatePorts( 1 )[ 0 ]; resetDbpath( externalPath ); -m = startMongod( "--port", port, "--dbpath", dbPath, "--nohttpinterface", "--noprealloc" , "--bind_ip", "127.0.0.1" ); +var m = MongoRunner.runMongod({dbpath: dbPath, noprealloc: "", bind_ip: "127.0.0.1"}); c = m.getDB( baseName ).getCollection( baseName ); c.save( { a: 1 } ); assert( c.findOne() ); -runMongoProgram( "mongodump", "--host", "127.0.0.1:" + port, "--out", externalPath ); +runMongoProgram( "mongodump", "--host", "127.0.0.1:" + m.port, "--out", externalPath ); c.drop(); -runMongoProgram( "mongorestore", "--host", "127.0.0.1:" + port, "--dir", externalPath ); +runMongoProgram( "mongorestore", "--host", "127.0.0.1:" + m.port, "--dir", externalPath ); assert.soon( "c.findOne()" , "mongodump then restore has no data w/sleep" ); assert( c.findOne() , "mongodump then restore has no data" ); assert.eq( 1 , c.findOne().a , "mongodump then restore has no broken data" ); @@ -34,10 +33,10 @@ assert.eq( 1 , c.findOne().a , "mongodump then restore has no broken data" ); resetDbpath( externalPath ); assert.eq( -1 , fileSize() , "mongoexport prep invalid" ); -runMongoProgram( "mongoexport", "--host", "127.0.0.1:" + port, "-d", baseName, "-c", baseName, "--out", externalFile ); +runMongoProgram( "mongoexport", "--host", "127.0.0.1:" + m.port, "-d", baseName, "-c", baseName, "--out", externalFile ); assert.lt( 10 , fileSize() , "file size changed" ); c.drop(); -runMongoProgram( "mongoimport", "--host", "127.0.0.1:" + port, "-d", baseName, "-c", baseName, "--file", externalFile ); +runMongoProgram( "mongoimport", "--host", "127.0.0.1:" + m.port, "-d", baseName, "-c", baseName, "--file", externalFile ); assert.soon( "c.findOne()" , "mongo import json A" ); assert( c.findOne() && 1 == c.findOne().a , "mongo import json B" ); |