[SERVER-18630] Replace runMongoProgram("mongod", ...) with MongoRunner.runMongod(...) Created: 22/May/15  Updated: 06/Dec/22  Resolved: 03/Dec/21

Status: Closed
Project: Core Server
Component/s: Testing Infrastructure
Affects Version/s: 3.1.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Max Hirschhorn Assignee: Backlog - Server Tooling and Methods (STM) (Inactive)
Resolution: Won't Fix Votes: 0
Labels: tig-mongorunner
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-17861 Change the default storage engine to ... Closed
Related
is related to SERVER-17450 Replace all instances of startMongod ... Closed
Assigned Teams:
Server Tooling & Methods
Operating System: ALL
Steps To Reproduce:

mongo --nodb --eval 'TestData = new Object(); TestData.storageEngine="wiredTiger"; MongoRunner.runMongod({})'

starts up a mongod with the wiredTiger storage engine.

mongo --nodb --eval 'TestData = new Object(); TestData.storageEngine="wiredTiger"; runMongoProgram("mongod", "--port", 27017)'

starts up a mongod with the default storage engine.

Participants:

 Description   

The runMongoProgram() shell helper is a generic construct to allow an arbitrary executable to be run. It does not configure the options of the mongod based on the global TestData object.



 Comments   
Comment by Max Hirschhorn [ 27/May/15 ]

To resolve the test failures in SERVER-17861, I made a more minimal change to enable runMongoProgram("mongod", ...) to use the storage engine that's configured on the global TestData object.

If we are still interested in standardizing how mongod's are started in tests (with the --repair option or not), then here's the initial approach I took to rewriting repair.js:

diff --git a/jstests/disk/repair.js b/jstests/disk/repair.js
index 0a92658..74ad631 100644
--- a/jstests/disk/repair.js
+++ b/jstests/disk/repair.js
@@ -2,46 +2,66 @@
 
 var baseName = "jstests_disk_repair";
 
-port = allocatePorts( 1 )[ 0 ];
-dbpath = MongoRunner.dataPath + baseName + "/";
-repairpath = dbpath + "repairDir/"
+var port = allocatePorts(1)[0];
+var dbpath = MongoRunner.dataPath + baseName + "/";
+var repairpath = dbpath + "repairDir/";
+var mongodOptions = {
+    port: port,
+    dbpath: dbpath,
+    nohttpinterface: "",
+    bind_ip: "127.0.0.1",
+    noCleanData: true,
+};
+
+function getRepairCmdLineArgs(options) {
+    // Add --repair to the command line invocation.
+    options = Object.merge(options, {repair: ""});
+
+    // Convert 'options' to an array.
+    var args = MongoRunner.arrOptions("mongod", options);
+
+    // Apply storage engine options to the command line invocation.
+    return MongoRunner.appendSetParameterArgs(args);
+}
+
+function check(conn) {
+    var pattern = new RegExp("^" + dbpath + "backup_");
+    listFiles(dbpath).forEach(function(file) {
+        assert(!pattern.test(file.name),
+               "backup directory " + file.name + " was found in the dbpath");
+    });
+    assert.eq(1, conn.getDB(baseName)[baseName].count());
+}
 
 resetDbpath( dbpath );
 resetDbpath( repairpath );
 
-m = startMongoProgram( "mongod", "--port", port, "--dbpath", dbpath, "--repairpath", repairpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
-db = m.getDB( baseName );
-db[ baseName ].save( {} );
-assert.commandWorked( db.runCommand( {repairDatabase:1, backupOriginalFiles:true} ) );
-function check() {
-    files = listFiles( dbpath );
-    for( f in files ) {
-        assert( ! new RegExp( "^" + dbpath + "backup_" ).test( files[ f ].name ), "backup dir in dbpath" );
-    }
-
-    assert.eq.automsg( "1", "db[ baseName ].count()" );
-}
-check();
-MongoRunner.stopMongod( port );
+var conn = MongoRunner.runMongod(Object.merge(mongodOptions, {repairpath: repairpath}));
+assert.writeOK(conn.getDB(baseName)[baseName].insert({}));
+assert.commandWorked(conn.getDB(baseName).runCommand({
+    repairDatabase: 1,
+    backupOriginalFiles: true,
+}));
+check(conn);
+MongoRunner.stopMongod(conn);
 
 resetDbpath( repairpath );
-m = startMongoProgram( "mongod", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
-db = m.getDB( baseName );
-assert.commandWorked( db.runCommand( {repairDatabase:1} ) );
-check();
-MongoRunner.stopMongod( port );
+conn = MongoRunner.runMongod(mongodOptions);
+assert.commandWorked(conn.getDB(baseName).runCommand({repairDatabase: 1}));
+check(conn);
+MongoRunner.stopMongod(conn);
 
 resetDbpath( repairpath );
-rc = runMongoProgram( "mongod", "--repair", "--port", port, "--dbpath", dbpath, "--repairpath", repairpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
-assert.eq.automsg( "0", "rc" );
-m = startMongoProgram( "mongod", "--port", port, "--dbpath", dbpath, "--repairpath", repairpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
-db = m.getDB( baseName );
-check();
-MongoRunner.stopMongod( port );
+var options = Object.merge(mongodOptions, {repairpath: repairpath});
+var exitCode = runMongoProgram.apply(null, getRepairCmdLineArgs(options));
+assert.eq(0, exitCode, "--repair did not execute successfully");
+conn = MongoRunner.runMongod(options);
+check(conn);
+MongoRunner.stopMongod(conn);
 
 resetDbpath( repairpath );
-rc = runMongoProgram( "mongod", "--repair", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
-assert.eq.automsg( "0", "rc" );
-m = startMongoProgram( "mongod", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
-db = m.getDB( baseName );
-check();
+exitCode = runMongoProgram.apply(null, getRepairCmdLineArgs(mongodOptions));
+assert.eq(0, exitCode, "--repair did not execute successfully");
+conn = MongoRunner.runMongod(mongodOptions);
+check(conn);
+MongoRunner.stopMongod(conn);
diff --git a/src/mongo/shell/servers.js b/src/mongo/shell/servers.js
index 1da9db3..5ce4a73 100755
--- a/src/mongo/shell/servers.js
+++ b/src/mongo/shell/servers.js
@@ -807,6 +807,8 @@ function appendSetParameterArgs(argArray) {
     return argArray;
 };
 
+MongoRunner.appendSetParameterArgs = appendSetParameterArgs;
+
 /**
  * Start a mongo process with a particular argument array.  If we aren't waiting for connect, 
  * return null.

Generated at Thu Feb 08 03:48:17 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.