diff options
35 files changed, 240 insertions, 210 deletions
diff --git a/jstests/auth/cluster_ip_allowlist.js b/jstests/auth/cluster_ip_allowlist.js index 80b6089de4d..1d39f4f5a38 100644 --- a/jstests/auth/cluster_ip_allowlist.js +++ b/jstests/auth/cluster_ip_allowlist.js @@ -6,13 +6,15 @@ 'use strict'; print("When allowlist is empty, the server does not start."); -assert.eq(null, - MongoRunner.runMongod( - {auth: null, keyFile: "jstests/libs/key1", clusterIpSourceAllowlist: ""})); +assert.throws(() => MongoRunner.runMongod( + {auth: null, keyFile: "jstests/libs/key1", clusterIpSourceAllowlist: ""}), + [], + "The server unexpectedly started"); // Check that the same behavior is seen with the deprecated 'clusterIpSourceWhiteList' flag. -assert.eq(null, - MongoRunner.runMongod( - {auth: null, keyFile: "jstests/libs/key1", clusterIpSourceWhitelist: ""})); +assert.throws(() => MongoRunner.runMongod( + {auth: null, keyFile: "jstests/libs/key1", clusterIpSourceWhitelist: ""}), + [], + "The server unexpectedly started"); function testIpAllowlist(description, allowlistString, authResult) { print(description); diff --git a/jstests/auth/validate_auth_schema_on_startup.js b/jstests/auth/validate_auth_schema_on_startup.js index e4c6c50fdcc..e66488f0909 100644 --- a/jstests/auth/validate_auth_schema_on_startup.js +++ b/jstests/auth/validate_auth_schema_on_startup.js @@ -32,7 +32,7 @@ assert.commandWorked(adminDB[authSchemaColl].update({_id: 'authSchema'}, {curren MongoRunner.stopMongod(mongod); // Confirm start up fails, even without --auth. -assert.eq(null, MongoRunner.runMongod({dbpath: dbpath, noCleanData: true})); +assert.throws(() => MongoRunner.runMongod({dbpath: dbpath, noCleanData: true})); // Confirm startup works with the flag to disable validation so the document can be repaired. mongod = MongoRunner.runMongod( diff --git a/jstests/disk/wt_table_checks.js b/jstests/disk/wt_table_checks.js index 9c2b4407323..854a7c6f39b 100644 --- a/jstests/disk/wt_table_checks.js +++ b/jstests/disk/wt_table_checks.js @@ -67,12 +67,11 @@ MongoRunner.stopMongod(conn); */ jsTest.log("Test 4."); -conn = startMongodOnExistingPath(dbpath, { - replSet: "mySet", - setParameter: - "failpoint.crashAfterUpdatingFirstTableLoggingSettings=" + tojson({"mode": "alwaysOn"}) -}); -assert(!conn); +assert.throws(() => startMongodOnExistingPath(dbpath, { + replSet: "mySet", + setParameter: "failpoint.crashAfterUpdatingFirstTableLoggingSettings=" + + tojson({"mode": "alwaysOn"}) + })); // Cannot use checkLog here as the server is no longer running. logContents = rawMongoProgramOutput(); diff --git a/jstests/fail_point/set_failpoint_through_set_parameter.js b/jstests/fail_point/set_failpoint_through_set_parameter.js index 4f8c311592b..f6482558263 100644 --- a/jstests/fail_point/set_failpoint_through_set_parameter.js +++ b/jstests/fail_point/set_failpoint_through_set_parameter.js @@ -6,13 +6,13 @@ "use strict"; -var assertStartupSucceeds = function(conn) { +function assertStartupSucceeds(conn) { assert.commandWorked(conn.adminCommand({hello: 1})); -}; +} -var assertStartupFails = function(conn) { - assert.eq(null, conn); -}; +function assertStartupFails(fun) { + assert.throws(fun, [], "Server started, when it was expected to fail"); +} var validFailpointPayload = {'mode': 'alwaysOn'}; var validFailpointPayloadWithData = {'mode': 'alwaysOn', 'data': {x: 1}}; @@ -26,18 +26,18 @@ configRS.initiate(); // Setting a failpoint via --setParameter fails if enableTestCommands is not on. TestData.enableTestCommands = false; -assertStartupFails( - MongoRunner.runMongod({setParameter: "failpoint.dummy=" + tojson(validFailpointPayload)})); -assertStartupFails(MongoRunner.runMongos({ +assertStartupFails(() => MongoRunner.runMongod( + {setParameter: "failpoint.dummy=" + tojson(validFailpointPayload)})); +assertStartupFails(() => MongoRunner.runMongos({ setParameter: "failpoint.dummy=" + tojson(validFailpointPayload), configdb: configRS.getURL() })); TestData.enableTestCommands = true; // Passing an invalid failpoint payload fails. -assertStartupFails( - MongoRunner.runMongod({setParameter: "failpoint.dummy=" + tojson(invalidFailpointPayload)})); -assertStartupFails(MongoRunner.runMongos({ +assertStartupFails(() => MongoRunner.runMongod( + {setParameter: "failpoint.dummy=" + tojson(invalidFailpointPayload)})); +assertStartupFails(() => MongoRunner.runMongos({ setParameter: "failpoint.dummy=" + tojson(invalidFailpointPayload), configdb: configRS.getURL() })); diff --git a/jstests/multiVersion/downgrade_shard_server_with_secondaryDelaySecs.js b/jstests/multiVersion/downgrade_shard_server_with_secondaryDelaySecs.js index e9a326cdcd6..5c15e7ca129 100644 --- a/jstests/multiVersion/downgrade_shard_server_with_secondaryDelaySecs.js +++ b/jstests/multiVersion/downgrade_shard_server_with_secondaryDelaySecs.js @@ -54,7 +54,7 @@ try { // succeeds. assert(false); } catch (e) { - assert(e.message.includes("Failed to connect")); + assert.eq("StopError", e.name); } // Restart with the 'latest' binary. diff --git a/jstests/multiVersion/genericSetFCVUsage/major_version_upgrade.js b/jstests/multiVersion/genericSetFCVUsage/major_version_upgrade.js index 503047bed60..a6e99d74bb4 100644 --- a/jstests/multiVersion/genericSetFCVUsage/major_version_upgrade.js +++ b/jstests/multiVersion/genericSetFCVUsage/major_version_upgrade.js @@ -49,7 +49,12 @@ for (let i = 0; i < versions.length; i++) { let mongodOptions = Object.extend({binVersion: version.binVersion}, defaultOptions); // Start a mongod with specified version. - let conn = MongoRunner.runMongod(mongodOptions); + let conn = null; + try { + conn = MongoRunner.runMongod(mongodOptions); + } catch (e) { + print(e); + } if ((conn === null) && (i > 0) && !authSchemaUpgraded) { // As of 4.0, mongod will refuse to start up with authSchema 3 diff --git a/jstests/multiVersion/genericSetFCVUsage/repair_feature_compatibility_version.js b/jstests/multiVersion/genericSetFCVUsage/repair_feature_compatibility_version.js index 2c379ae0ab1..d7567731ebe 100644 --- a/jstests/multiVersion/genericSetFCVUsage/repair_feature_compatibility_version.js +++ b/jstests/multiVersion/genericSetFCVUsage/repair_feature_compatibility_version.js @@ -26,10 +26,10 @@ let doStartupFailTests = function(version, dbpath) { // Now attempt to start up a new mongod without clearing the data files from 'dbpath', which // contain the admin database but are missing the FCV document. The mongod should fail to // start up if there is a non-local collection and the FCV document is missing. - let conn = MongoRunner.runMongod({dbpath: dbpath, binVersion: version, noCleanData: true}); - assert.eq(null, - conn, - "expected mongod to fail when data files are present but no FCV document is found."); + assert.throws( + () => MongoRunner.runMongod({dbpath: dbpath, binVersion: version, noCleanData: true}), + [], + "expected mongod to fail when data files are present but no FCV document is found."); }; /** diff --git a/jstests/multiVersion/skip_level_upgrade.js b/jstests/multiVersion/skip_level_upgrade.js index ec313e3f4a0..1a89f5a428e 100644 --- a/jstests/multiVersion/skip_level_upgrade.js +++ b/jstests/multiVersion/skip_level_upgrade.js @@ -60,8 +60,7 @@ for (let i = 0; i < versions.length; i++) { // Restart the mongod with the latest binary version on the old version's data files. // Should fail due to being a skip level upgrade. mongodOptions = Object.extend({binVersion: 'latest'}, defaultOptions); - conn = MongoRunner.runMongod(mongodOptions); - assert.eq(null, conn); + assert.throws(() => MongoRunner.runMongod(mongodOptions)); // Restart the mongod with the latest version with --repair. Should fail due to being a // skip level upgrade. diff --git a/jstests/noPassthrough/compression_options.js b/jstests/noPassthrough/compression_options.js index b83b75da8c2..bfdb4be7299 100644 --- a/jstests/noPassthrough/compression_options.js +++ b/jstests/noPassthrough/compression_options.js @@ -35,7 +35,7 @@ var runTest = function(optionValue, expected) { MongoRunner.stopMongod(mongo); }; -assert.isnull(MongoRunner.runMongod({networkMessageCompressors: "snappy,disabled"})); +assert.throws(() => MongoRunner.runMongod({networkMessageCompressors: "snappy,disabled"})); runTest("snappy", ["snappy"]); runTest("disabled", undefined); diff --git a/jstests/noPassthrough/dir_per_db_and_split.js b/jstests/noPassthrough/dir_per_db_and_split.js index 2704afa4aa2..201301857b1 100644 --- a/jstests/noPassthrough/dir_per_db_and_split.js +++ b/jstests/noPassthrough/dir_per_db_and_split.js @@ -17,9 +17,10 @@ if (!jsTest.options().storageEngine || jsTest.options().storageEngine === "wired // Subsequent attempts to start server using same dbpath but different // wiredTigerDirectoryForIndexes and directoryperdb options should fail. - assert.isnull(MongoRunner.runMongod({dbpath: dbpath, port: m.port, restart: true})); - assert.isnull( - MongoRunner.runMongod({dbpath: dbpath, port: m.port, restart: true, directoryperdb: ''})); - assert.isnull(MongoRunner.runMongod( - {dbpath: dbpath, port: m.port, restart: true, wiredTigerDirectoryForIndexes: ''})); + assert.throws(() => MongoRunner.runMongod({dbpath: dbpath, port: m.port, restart: true})); + assert.throws(() => MongoRunner.runMongod( + {dbpath: dbpath, port: m.port, restart: true, directoryperdb: ''})); + assert.throws( + () => MongoRunner.runMongod( + {dbpath: dbpath, port: m.port, restart: true, wiredTigerDirectoryForIndexes: ''})); } diff --git a/jstests/noPassthrough/directoryperdb.js b/jstests/noPassthrough/directoryperdb.js index 5e1111f61cd..918e53e5d84 100644 --- a/jstests/noPassthrough/directoryperdb.js +++ b/jstests/noPassthrough/directoryperdb.js @@ -75,5 +75,5 @@ checkDirRemoved(dbname, dbpath); MongoRunner.stopMongod(m); // Subsequent attempt to start server using same dbpath without directoryperdb should fail. -assert.isnull(MongoRunner.runMongod({dbpath: dbpath, restart: true})); +assert.throws(() => MongoRunner.runMongod({dbpath: dbpath, restart: true})); }()); diff --git a/jstests/noPassthrough/disabled_test_parameters.js b/jstests/noPassthrough/disabled_test_parameters.js index 8dde184b6c5..0f71810db03 100644 --- a/jstests/noPassthrough/disabled_test_parameters.js +++ b/jstests/noPassthrough/disabled_test_parameters.js @@ -4,7 +4,7 @@ 'use strict'; function assertFails(opts) { - assert.eq(null, MongoRunner.runMongod(opts), "Mongod startup up"); + assert.throws(() => MongoRunner.runMongod(opts), [], "Mongod startup up"); } function assertStarts(opts) { diff --git a/jstests/noPassthrough/internal_validate_features_as_master.js b/jstests/noPassthrough/internal_validate_features_as_master.js index 8bc00fa0d40..7aca471e106 100644 --- a/jstests/noPassthrough/internal_validate_features_as_master.js +++ b/jstests/noPassthrough/internal_validate_features_as_master.js @@ -16,13 +16,15 @@ assert.eq(res.internalValidateFeaturesAsMaster, true); MongoRunner.stopMongod(conn); // internalValidateFeaturesAsMaster cannot be set with --replSet. -conn = MongoRunner.runMongod( - {replSet: "replSetName", setParameter: "internalValidateFeaturesAsMaster=0"}); -assert.eq(null, conn, "mongod was unexpectedly able to start up"); +assert.throws(() => MongoRunner.runMongod( + {replSet: "replSetName", setParameter: "internalValidateFeaturesAsMaster=0"}), + [], + "mongod was unexpectedly able to start up"); -conn = MongoRunner.runMongod( - {replSet: "replSetName", setParameter: "internalValidateFeaturesAsMaster=1"}); -assert.eq(null, conn, "mongod was unexpectedly able to start up"); +assert.throws(() => MongoRunner.runMongod( + {replSet: "replSetName", setParameter: "internalValidateFeaturesAsMaster=1"}), + [], + "mongod was unexpectedly able to start up"); // internalValidateFeaturesAsMaster cannot be set via runtime parameter. conn = MongoRunner.runMongod({}); diff --git a/jstests/noPassthrough/internal_validate_features_as_primary.js b/jstests/noPassthrough/internal_validate_features_as_primary.js index 5dbc7154e39..f910414eef0 100644 --- a/jstests/noPassthrough/internal_validate_features_as_primary.js +++ b/jstests/noPassthrough/internal_validate_features_as_primary.js @@ -43,19 +43,22 @@ assert.eq(res.internalValidateFeaturesAsPrimary, true); MongoRunner.stopMongod(conn); // internalValidateFeaturesAsPrimary cannot be set with --replSet. -conn = MongoRunner.runMongod( - {replSet: "replSetName", setParameter: "internalValidateFeaturesAsPrimary=0"}); -assert.eq(null, conn, "mongod was unexpectedly able to start up"); +assert.throws(() => MongoRunner.runMongod( + {replSet: "replSetName", setParameter: "internalValidateFeaturesAsPrimary=0"}), + [], + "mongod was unexpectedly able to start up"); -conn = MongoRunner.runMongod( - {replSet: "replSetName", setParameter: "internalValidateFeaturesAsPrimary=1"}); -assert.eq(null, conn, "mongod was unexpectedly able to start up"); +assert.throws(() => MongoRunner.runMongod( + {replSet: "replSetName", setParameter: "internalValidateFeaturesAsPrimary=1"}), + [], + "mongod was unexpectedly able to start up"); // Correct error message is logged based on parameter name. conn = MongoRunner.runMongod({}); joinShell = startParallelShell(() => { - MongoRunner.runMongod( - {replSet: "replSetName", setParameter: "internalValidateFeaturesAsPrimary=0"}); + assert.throws( + () => MongoRunner.runMongod( + {replSet: "replSetName", setParameter: "internalValidateFeaturesAsPrimary=0"})); }, conn.port); joinShell(); let joinShellOutput = rawMongoProgramOutput(); @@ -66,8 +69,9 @@ assert(!joinShellOutput.match( clearRawMongoProgramOutput(); joinShell = startParallelShell(() => { - MongoRunner.runMongod( - {replSet: "replSetName", setParameter: "internalValidateFeaturesAsMaster=0"}); + assert.throws( + () => MongoRunner.runMongod( + {replSet: "replSetName", setParameter: "internalValidateFeaturesAsMaster=0"})); }, conn.port); joinShell(); joinShellOutput = rawMongoProgramOutput(); diff --git a/jstests/noPassthrough/libs/server_parameter_helpers.js b/jstests/noPassthrough/libs/server_parameter_helpers.js index 8101f6c2659..0713aabfa18 100644 --- a/jstests/noPassthrough/libs/server_parameter_helpers.js +++ b/jstests/noPassthrough/libs/server_parameter_helpers.js @@ -96,12 +96,11 @@ function testNumericServerParameter(parameterName, if (hasLowerBound) { jsTest.log("Checking that '" + parameterName + "' cannot be set below bounds to '" + lowerOutOfBounds + "' on startup"); - let conn3 = - MongoRunner.runMongod({setParameter: parameterName + "=" + lowerOutOfBounds}); - assert.eq(null, - conn3, - "expected mongod to fail to startup with an invalid '" + parameterName + "'" + - " server parameter setting '" + lowerOutOfBounds + "'."); + assert.throws( + () => MongoRunner.runMongod({setParameter: parameterName + "=" + lowerOutOfBounds}), + [], + "expected mongod to fail to startup with an invalid '" + parameterName + "'" + + " server parameter setting '" + lowerOutOfBounds + "'."); } if (hasUpperBound) { diff --git a/jstests/noPassthrough/lock_file_fail_to_open.js b/jstests/noPassthrough/lock_file_fail_to_open.js index a53c6688b9f..83df3ed80bd 100644 --- a/jstests/noPassthrough/lock_file_fail_to_open.js +++ b/jstests/noPassthrough/lock_file_fail_to_open.js @@ -13,10 +13,7 @@ var mongo1 = MongoRunner.runMongod({dbpath: dbPath, waitForConnect: true}); clearRawMongoProgramOutput(); // Start another one which should fail to start as there is already a lockfile in its // dbpath. -var mongo2 = null; -mongo2 = MongoRunner.runMongod({dbpath: dbPath, noCleanData: true}); -// We should have failed to start. -assert(mongo2 === null); +assert.throws(() => MongoRunner.runMongod({dbpath: dbPath, noCleanData: true})); var logContents = rawMongoProgramOutput(); assert(logContents.indexOf("Unable to lock the lock file") > 0 || diff --git a/jstests/noPassthrough/max_acceptable_logical_clock_drift_secs_parameter.js b/jstests/noPassthrough/max_acceptable_logical_clock_drift_secs_parameter.js index 8797d39b4a5..78385d2b124 100644 --- a/jstests/noPassthrough/max_acceptable_logical_clock_drift_secs_parameter.js +++ b/jstests/noPassthrough/max_acceptable_logical_clock_drift_secs_parameter.js @@ -10,17 +10,21 @@ "use strict"; // maxAcceptableLogicalClockDriftSecs cannot be negative, zero, or a non-number. -let conn = MongoRunner.runMongod({setParameter: {maxAcceptableLogicalClockDriftSecs: -1}}); -assert.eq(null, conn, "expected server to reject negative maxAcceptableLogicalClockDriftSecs"); +assert.throws(() => MongoRunner.runMongod({setParameter: {maxAcceptableLogicalClockDriftSecs: -1}}), + [], + "expected server to reject negative maxAcceptableLogicalClockDriftSecs"); -conn = MongoRunner.runMongod({setParameter: {maxAcceptableLogicalClockDriftSecs: 0}}); -assert.eq(null, conn, "expected server to reject zero maxAcceptableLogicalClockDriftSecs"); +assert.throws(() => MongoRunner.runMongod({setParameter: {maxAcceptableLogicalClockDriftSecs: 0}}), + [], + "expected server to reject zero maxAcceptableLogicalClockDriftSecs"); -conn = MongoRunner.runMongod({setParameter: {maxAcceptableLogicalClockDriftSecs: "value"}}); -assert.eq(null, conn, "expected server to reject non-numeric maxAcceptableLogicalClockDriftSecs"); +assert.throws( + () => MongoRunner.runMongod({setParameter: {maxAcceptableLogicalClockDriftSecs: "value"}}), + [], + "expected server to reject non-numeric maxAcceptableLogicalClockDriftSecs"); // Any positive number is valid. -conn = MongoRunner.runMongod({setParameter: {maxAcceptableLogicalClockDriftSecs: 1}}); +let conn = MongoRunner.runMongod({setParameter: {maxAcceptableLogicalClockDriftSecs: 1}}); assert.neq(null, conn, "failed to start mongod with valid maxAcceptableLogicalClockDriftSecs"); MongoRunner.stopMongod(conn); diff --git a/jstests/noPassthrough/max_bson_depth_parameter.js b/jstests/noPassthrough/max_bson_depth_parameter.js index 3aef0995d34..8914dd2bd1b 100644 --- a/jstests/noPassthrough/max_bson_depth_parameter.js +++ b/jstests/noPassthrough/max_bson_depth_parameter.js @@ -45,9 +45,12 @@ assert.commandFailedWithCode( // Restart mongod with a negative maximum BSON depth and test that it fails to start. MongoRunner.stopMongod(conn); -conn = MongoRunner.runMongod({setParameter: "maxBSONDepth=-4"}); -assert.eq(null, conn, "Expected mongod to fail at startup because depth was negative"); -conn = MongoRunner.runMongod({setParameter: "maxBSONDepth=1"}); -assert.eq(null, conn, "Expected mongod to fail at startup because depth was too low"); +assert.throws(() => MongoRunner.runMongod({setParameter: "maxBSONDepth=-4"}), + [], + "Expected mongod to fail at startup because depth was negative"); + +assert.throws(() => MongoRunner.runMongod({setParameter: "maxBSONDepth=1"}), + [], + "Expected mongod to fail at startup because depth was too low"); }()); diff --git a/jstests/noPassthrough/parse_zone_info.js b/jstests/noPassthrough/parse_zone_info.js index deb2d31725c..bdfdfd5cd34 100644 --- a/jstests/noPassthrough/parse_zone_info.js +++ b/jstests/noPassthrough/parse_zone_info.js @@ -1,20 +1,24 @@ // Tests the parsing of the timeZoneInfo parameter and file use. (function() { // Test that a bad file causes startup to fail. -let conn = MongoRunner.runMongod({timeZoneInfo: "jstests/libs/config_files/bad_timezone_info"}); -assert.eq(conn, null, "expected launching mongod with bad timezone rules to fail"); +assert.throws( + () => MongoRunner.runMongod({timeZoneInfo: "jstests/libs/config_files/bad_timezone_info"}), + [], + "expected launching mongod with bad timezone rules to fail"); assert.neq(-1, rawMongoProgramOutput().search(/Fatal assertion.*40475/)); // Test that a non-existent directory causes startup to fail. -conn = MongoRunner.runMongod({timeZoneInfo: "jstests/libs/config_files/missing_directory"}); -assert.eq(conn, null, "expected launching mongod with bad timezone rules to fail"); +assert.throws( + () => MongoRunner.runMongod({timeZoneInfo: "jstests/libs/config_files/missing_directory"}), + [], + "expected launching mongod with bad timezone rules to fail"); // Look for either old or new error message assert(rawMongoProgramOutput().includes("Error creating service context") || rawMongoProgramOutput().includes("Failed to create service context")); function testWithGoodTimeZoneDir(tz_good_path) { - conn = MongoRunner.runMongod({timeZoneInfo: tz_good_path}); + let conn = MongoRunner.runMongod({timeZoneInfo: tz_good_path}); assert.neq(conn, null, "expected launching mongod with good timezone rules to succeed"); // Test that can use file-provided timezones in an expression. diff --git a/jstests/noPassthrough/queryable_backup_mode_incompatible_options.js b/jstests/noPassthrough/queryable_backup_mode_incompatible_options.js index d344d2648c2..ea2a4ef5f0b 100644 --- a/jstests/noPassthrough/queryable_backup_mode_incompatible_options.js +++ b/jstests/noPassthrough/queryable_backup_mode_incompatible_options.js @@ -24,39 +24,33 @@ var coll = conn.getCollection('test.foo'); coll.insertOne({a: 1}); MongoRunner.stopMongod(conn); -conn = MongoRunner.runMongod( - {dbpath: dbdir, noCleanData: true, queryableBackupMode: '', replSet: 'bar'}); - -assert.eq(null, - conn, - "mongod should fail to start when both --queryableBackupMode and --replSet are provided"); - -conn = MongoRunner.runMongod( - {dbpath: dbdir, noCleanData: true, queryableBackupMode: '', configsvr: ''}); - -assert.eq( - null, - conn, +assert.throws( + () => MongoRunner.runMongod( + {dbpath: dbdir, noCleanData: true, queryableBackupMode: '', replSet: 'bar'}), + [], + "mongod should fail to start when both --queryableBackupMode and --replSet are provided"); + +assert.throws( + () => MongoRunner.runMongod( + {dbpath: dbdir, noCleanData: true, queryableBackupMode: '', configsvr: ''}), + [], "mongod should fail to start when both --queryableBackupMode and --configsvr are provided"); -conn = - MongoRunner.runMongod({dbpath: dbdir, noCleanData: true, queryableBackupMode: '', upgrade: ''}); - -assert.eq(null, - conn, - "mongod should fail to start when both --queryableBackupMode and --upgrade are provided"); - -conn = - MongoRunner.runMongod({dbpath: dbdir, noCleanData: true, queryableBackupMode: '', repair: ''}); - -assert.eq(null, - conn, - "mongod should fail to start when both --queryableBackupMode and --repair are provided"); - -conn = - MongoRunner.runMongod({dbpath: dbdir, noCleanData: true, queryableBackupMode: '', profile: 1}); - -assert.eq(null, - conn, - "mongod should fail to start when both --queryableBackupMode and --profile are provided"); +assert.throws( + () => MongoRunner.runMongod( + {dbpath: dbdir, noCleanData: true, queryableBackupMode: '', upgrade: ''}), + [], + "mongod should fail to start when both --queryableBackupMode and --upgrade are provided"); + +assert.throws( + () => MongoRunner.runMongod( + {dbpath: dbdir, noCleanData: true, queryableBackupMode: '', repair: ''}), + [], + "mongod should fail to start when both --queryableBackupMode and --repair are provided"); + +assert.throws( + () => MongoRunner.runMongod( + {dbpath: dbdir, noCleanData: true, queryableBackupMode: '', profile: 1}), + [], + "mongod should fail to start when both --queryableBackupMode and --profile are provided"); })(); diff --git a/jstests/noPassthrough/repl_write_threads_start_param.js b/jstests/noPassthrough/repl_write_threads_start_param.js index f80f0f81655..7e52dfc5160 100644 --- a/jstests/noPassthrough/repl_write_threads_start_param.js +++ b/jstests/noPassthrough/repl_write_threads_start_param.js @@ -9,23 +9,23 @@ // too low a count clearRawMongoProgramOutput(); -var mongo = MongoRunner.runMongod({setParameter: 'replWriterThreadCount=0'}); -assert.soon(function() { - return rawMongoProgramOutput().match( - "Invalid value for parameter replWriterThreadCount: 0 is not greater than or equal to 1"); -}, "mongod started with too low a value for replWriterThreadCount"); +assert.throws(() => MongoRunner.runMongod({setParameter: 'replWriterThreadCount=0'})); +assert( + rawMongoProgramOutput().match( + "Invalid value for parameter replWriterThreadCount: 0 is not greater than or equal to 1"), + "mongod started with too low a value for replWriterThreadCount"); // too high a count clearRawMongoProgramOutput(); -mongo = MongoRunner.runMongod({setParameter: 'replWriterThreadCount=257'}); -assert.soon(function() { - return rawMongoProgramOutput().match( - "Invalid value for parameter replWriterThreadCount: 257 is not less than or equal to 256"); -}, "mongod started with too high a value for replWriterThreadCount"); +assert.throws(() => MongoRunner.runMongod({setParameter: 'replWriterThreadCount=257'})); +assert( + rawMongoProgramOutput().match( + "Invalid value for parameter replWriterThreadCount: 257 is not less than or equal to 256"), + "mongod started with too high a value for replWriterThreadCount"); // proper count clearRawMongoProgramOutput(); -mongo = MongoRunner.runMongod({setParameter: 'replWriterThreadCount=24'}); +let mongo = MongoRunner.runMongod({setParameter: 'replWriterThreadCount=24'}); assert.neq(null, mongo, "mongod failed to start with a suitable replWriterThreadCount value"); assert(!rawMongoProgramOutput().match("Invalid value for parameter replWriterThreadCount"), "despite accepting the replWriterThreadCount value, mongod logged an error"); diff --git a/jstests/noPassthrough/require_api_version.js b/jstests/noPassthrough/require_api_version.js index aafe763f3a4..661f33ea886 100644 --- a/jstests/noPassthrough/require_api_version.js +++ b/jstests/noPassthrough/require_api_version.js @@ -126,26 +126,24 @@ function runTest(db, supportsTransctions, writeConcern = {}, secondaries = []) { } function requireApiVersionOnShardOrConfigServerTest() { - let shardsvrMongod = - MongoRunner.runMongod({shardsvr: "", setParameter: {"requireApiVersion": true}}); - assert.eq(null, - shardsvrMongod, - "mongod should not be able to start up with --shardsvr and requireApiVersion=true"); - - let configsvrMongod = - MongoRunner.runMongod({configsvr: "", setParameter: {"requireApiVersion": 1}}); - assert.eq(null, - configsvrMongod, - "mongod should not be able to start up with --configsvr and requireApiVersion=true"); - - shardsvrMongod = MongoRunner.runMongod({shardsvr: ""}); + assert.throws( + () => MongoRunner.runMongod({shardsvr: "", setParameter: {"requireApiVersion": true}}), + [], + "mongod should not be able to start up with --shardsvr and requireApiVersion=true"); + + assert.throws( + () => MongoRunner.runMongod({configsvr: "", setParameter: {"requireApiVersion": 1}}), + [], + "mongod should not be able to start up with --configsvr and requireApiVersion=true"); + + const shardsvrMongod = MongoRunner.runMongod({shardsvr: ""}); assert.neq(null, shardsvrMongod, "mongod was not able to start up"); assert.commandFailed( shardsvrMongod.adminCommand({setParameter: 1, requireApiVersion: true}), "should not be able to set requireApiVersion=true on mongod that was started with --shardsvr"); MongoRunner.stopMongod(shardsvrMongod); - configsvrMongod = MongoRunner.runMongod({configsvr: ""}); + const configsvrMongod = MongoRunner.runMongod({configsvr: ""}); assert.neq(null, configsvrMongod, "mongod was not able to start up"); assert.commandFailed( configsvrMongod.adminCommand({setParameter: 1, requireApiVersion: 1}), diff --git a/jstests/noPassthrough/skip_sharding_configuration_checks.js b/jstests/noPassthrough/skip_sharding_configuration_checks.js index 58083937ed0..62553d42432 100644 --- a/jstests/noPassthrough/skip_sharding_configuration_checks.js +++ b/jstests/noPassthrough/skip_sharding_configuration_checks.js @@ -20,13 +20,11 @@ function expectState(rst, state) { }); } -let configSvr = - MongoRunner.runMongod({configsvr: "", setParameter: 'skipShardingConfigurationChecks=true'}); -assert.eq(configSvr, null); +assert.throws(() => MongoRunner.runMongod( + {configsvr: "", setParameter: 'skipShardingConfigurationChecks=true'})); -let shardSvr = - MongoRunner.runMongod({shardsvr: "", setParameter: 'skipShardingConfigurationChecks=true'}); -assert.eq(shardSvr, null); +assert.throws(() => MongoRunner.runMongod( + {shardsvr: "", setParameter: 'skipShardingConfigurationChecks=true'})); var st = new ShardingTest({name: "skipConfig", shards: {rs0: {nodes: 1}}}); var configRS = st.configRS; diff --git a/jstests/noPassthrough/split_collections_and_indexes.js b/jstests/noPassthrough/split_collections_and_indexes.js index 9ad12b3eb48..b0b8378bf50 100644 --- a/jstests/noPassthrough/split_collections_and_indexes.js +++ b/jstests/noPassthrough/split_collections_and_indexes.js @@ -17,8 +17,12 @@ if (!jsTest.options().storageEngine || jsTest.options().storageEngine === "wired // Subsequent attempts to start server using same dbpath but different // wiredTigerDirectoryForIndexes and directoryperdb options should fail. - assert.isnull(MongoRunner.runMongod({dbpath: dbpath, restart: true})); - assert.isnull(MongoRunner.runMongod({dbpath: dbpath, restart: true, directoryperdb: ''})); - assert.isnull(MongoRunner.runMongod( - {dbpath: dbpath, restart: true, wiredTigerDirectoryForIndexes: '', directoryperdb: ''})); + assert.throws(() => MongoRunner.runMongod({dbpath: dbpath, restart: true})); + assert.throws(() => MongoRunner.runMongod({dbpath: dbpath, restart: true, directoryperdb: ''})); + assert.throws(() => MongoRunner.runMongod({ + dbpath: dbpath, + restart: true, + wiredTigerDirectoryForIndexes: '', + directoryperdb: '' + })); } diff --git a/jstests/noPassthrough/traffic_recording.js b/jstests/noPassthrough/traffic_recording.js index 2021ac65e31..e3cfc33d819 100644 --- a/jstests/noPassthrough/traffic_recording.js +++ b/jstests/noPassthrough/traffic_recording.js @@ -92,12 +92,14 @@ function runTest(client, restartCommand) { if (m) { MongoRunner.stopMongod(m, null, {user: 'admin', pwd: 'pass'}); } - m = MongoRunner.runMongod({auth: "", setParameter: setParams}); - - if (m) { - m.getDB("admin").createUser({user: "admin", pwd: "pass", roles: jsTest.adminUserRoles}); + try { + m = MongoRunner.runMongod({auth: "", setParameter: setParams}); + } catch (e) { + return null; } + m.getDB("admin").createUser({user: "admin", pwd: "pass", roles: jsTest.adminUserRoles}); + return m; }); diff --git a/jstests/noPassthrough/umask.js b/jstests/noPassthrough/umask.js index 80ff14ce94c..12e0afe1f30 100644 --- a/jstests/noPassthrough/umask.js +++ b/jstests/noPassthrough/umask.js @@ -90,7 +90,7 @@ mongodOptions.setParameter = { honorSystemUmask: true, processUmask: '022', }; -assert.eq(null, MongoRunner.runMongod(mongodOptions)); +assert.throws(() => MongoRunner.runMongod(mongodOptions)); // Okay to start with both if honorSystemUmask is false. mongodOptions.setParameter = { diff --git a/jstests/noPassthrough/wt_nojournal_skip_recovery.js b/jstests/noPassthrough/wt_nojournal_skip_recovery.js index b33e354860f..0228c859eb0 100644 --- a/jstests/noPassthrough/wt_nojournal_skip_recovery.js +++ b/jstests/noPassthrough/wt_nojournal_skip_recovery.js @@ -67,13 +67,14 @@ assert.neq(0, exitCode, 'expected shell to exit abnormally due to mongod being t // Restart the mongod with journaling disabled, but configure it to error if the database needs // recovery. -conn = MongoRunner.runMongod({ +assert.throws(() => MongoRunner.runMongod({ dbpath: dbpath, noCleanData: true, nojournal: '', wiredTigerEngineConfigString: 'log=(recover=error)', -}); -assert.eq(null, conn, 'mongod should not have started up because it requires recovery'); +}), + [], + 'mongod should not have started up because it requires recovery'); // Remove the journal files. assert(removeFile(dbpath + '/journal'), 'failed to remove the journal directory'); diff --git a/jstests/sharding/time_zone_info_mongos.js b/jstests/sharding/time_zone_info_mongos.js index df2bcc89214..8851297628a 100644 --- a/jstests/sharding/time_zone_info_mongos.js +++ b/jstests/sharding/time_zone_info_mongos.js @@ -24,13 +24,17 @@ function testWithGoodTimeZoneDir(tzGoodInfoDir) { assert.eq(mongosCfg.parsed.processManagement.timeZoneInfo, tzGoodInfoDir); // Test that a bad timezone file causes mongoS startup to fail. - let conn = MongoRunner.runMongos({configdb: st.configRS.getURL(), timeZoneInfo: tzBadInfo}); - assert.eq(conn, null, "expected launching mongos with bad timezone rules to fail"); + assert.throws( + () => MongoRunner.runMongos({configdb: st.configRS.getURL(), timeZoneInfo: tzBadInfo}), + [], + "expected launching mongos with bad timezone rules to fail"); assert.neq(-1, rawMongoProgramOutput().search(/Fatal assertion.*40475/)); // Test that a non-existent timezone directory causes mongoS startup to fail. - conn = MongoRunner.runMongos({configdb: st.configRS.getURL(), timeZoneInfo: tzNoInfo}); - assert.eq(conn, null, "expected launching mongos with bad timezone rules to fail"); + assert.throws( + () => MongoRunner.runMongos({configdb: st.configRS.getURL(), timeZoneInfo: tzNoInfo}), + [], + "expected launching mongos with bad timezone rules to fail"); // Look for either old or new error message assert(rawMongoProgramOutput().includes("Error creating service context") || rawMongoProgramOutput().includes("Failed to create service context")); diff --git a/jstests/ssl/macos_encrypted_pem.js b/jstests/ssl/macos_encrypted_pem.js index ca484fe2582..3db467dea3e 100644 --- a/jstests/ssl/macos_encrypted_pem.js +++ b/jstests/ssl/macos_encrypted_pem.js @@ -13,8 +13,7 @@ requireSSLProvider('apple', function() { sslCAFile: "jstests/libs/ca.pem", }); - const mongod = MongoRunner.runMongod(config); - assert(mongod === null, "MongoD unexpectedly started up"); + assert.throws(() => MongoRunner.runMongod(config), [], "MongoD unexpectedly started up"); assert.eq(rawMongoProgramOutput().includes( "Using encrypted PKCS#1/PKCS#8 PEM files is not supported on this platform"), diff --git a/jstests/ssl/ssl_fips.js b/jstests/ssl/ssl_fips.js index e1736f03e5e..818f93b21e2 100644 --- a/jstests/ssl/ssl_fips.js +++ b/jstests/ssl/ssl_fips.js @@ -1,36 +1,30 @@ -// Test mongod start with FIPS mode enabled -var port = allocatePort(); -var md = MongoRunner.runMongod({ - port: port, - sslMode: "requireSSL", - sslPEMKeyFile: "jstests/libs/server.pem", - sslCAFile: "jstests/libs/ca.pem", - sslFIPSMode: "" -}); - -var mongo = runMongoProgram("mongo", - "--port", - port, - "--ssl", - "--sslAllowInvalidCertificates", - "--sslPEMKeyFile", - "jstests/libs/client.pem", - "--sslFIPSMode", - "--eval", - ";"); +(function() { -// if mongo shell didn't start/connect properly -if (mongo != 0) { +// Test mongod start with FIPS mode enabled +const port = allocatePort(); +let md = undefined; +try { + md = MongoRunner.runMongod({ + port: port, + sslMode: "requireSSL", + sslPEMKeyFile: "jstests/libs/server.pem", + sslCAFile: "jstests/libs/ca.pem", + sslFIPSMode: "" + }); +} catch (e) { print("mongod failed to start, checking for FIPS support"); - mongoOutput = rawMongoProgramOutput(); + let mongoOutput = rawMongoProgramOutput(); assert(mongoOutput.match(/this version of mongodb was not compiled with FIPS support/) || mongoOutput.match(/FIPS modes is not enabled on the operating system/) || mongoOutput.match(/FIPS_mode_set:fips mode not supported/)); -} else { - // verify that auth works, SERVER-18051 - md.getDB("admin").createUser({user: "root", pwd: "root", roles: ["root"]}); - assert(md.getDB("admin").auth("root", "root"), "auth failed"); - - // kill mongod - MongoRunner.stopMongod(md); + return; } +assert(md); + +// verify that auth works, SERVER-18051 +md.getDB("admin").createUser({user: "root", pwd: "root", roles: ["root"]}); +assert(md.getDB("admin").auth("root", "root"), "auth failed"); + +// kill mongod +MongoRunner.stopMongod(md); +})(); diff --git a/jstests/ssl/ssl_invalid_server_cert.js b/jstests/ssl/ssl_invalid_server_cert.js index 96cca8c0075..6bb8cef2c57 100644 --- a/jstests/ssl/ssl_invalid_server_cert.js +++ b/jstests/ssl/ssl_invalid_server_cert.js @@ -7,7 +7,13 @@ function runTest(name, config, expect) { jsTest.log('Running test: ' + name); clearRawMongoProgramOutput(); - const mongod = MongoRunner.runMongod(config); + let mongod = null; + let err = null; + try { + mongod = MongoRunner.runMongod(config); + } catch (e) { + err = e; + } assert.eq(null, mongod, 'Mongod started unexpectedly'); const output = rawMongoProgramOutput(); diff --git a/jstests/ssl/ssl_without_ca.js b/jstests/ssl/ssl_without_ca.js index ef3f64949aa..9b0a62a5250 100644 --- a/jstests/ssl/ssl_without_ca.js +++ b/jstests/ssl/ssl_without_ca.js @@ -37,8 +37,9 @@ MongoRunner.stopMongod(conn); jsTest.log("Assert mongod doesn\'t start with CA file missing and clusterAuthMode=x509."); var sslParams = {clusterAuthMode: 'x509', sslMode: 'requireSSL', sslPEMKeyFile: SERVER_CERT}; -var conn = MongoRunner.runMongod(sslParams); -assert.isnull(conn, "server started with x509 clusterAuthMode but no CA file"); +assert.throws(() => MongoRunner.runMongod(sslParams), + [], + "server started with x509 clusterAuthMode but no CA file"); jsTest.log("Assert mongos doesn\'t start with CA file missing and clusterAuthMode=x509."); @@ -60,13 +61,15 @@ var startOptions = { var configRS = new ReplSetTest(rstOptions); configRS.startSet(startOptions); -var mongos = MongoRunner.runMongos({ + +// Make sure the mongoS failed to start up for the proper reason. +assert.throws(() => MongoRunner.runMongos({ clusterAuthMode: 'x509', sslMode: 'requireSSL', sslPEMKeyFile: SERVER_CERT, configdb: configRS.getURL() -}); -// Make sure the mongoS failed to start up for the proper reason. -assert.eq(null, mongos, "mongos started with x509 clusterAuthMode but no CA file"); +}), + [], + "mongos started with x509 clusterAuthMode but no CA file"); assert.neq(-1, rawMongoProgramOutput().search("No TLS certificate validation can be performed")); -configRS.stopSet();
\ No newline at end of file +configRS.stopSet(); diff --git a/jstests/ssl/x509_enforce_user_cluster_separation.js b/jstests/ssl/x509_enforce_user_cluster_separation.js index a27ca670be3..1b7f4bd5731 100644 --- a/jstests/ssl/x509_enforce_user_cluster_separation.js +++ b/jstests/ssl/x509_enforce_user_cluster_separation.js @@ -99,8 +99,9 @@ function runMongodTest(desc, func) { function runMongodFailTest(desc, options) { print(desc); - const mongo = MongoRunner.runMongod(Object.merge(mongodOptions, options)); - assert(!mongo, "MongoD started successfully with bad options"); + assert.throws(() => MongoRunner.runMongod(Object.merge(mongodOptions, options)), + [], + "MongoD started successfully with bad options"); } function runMongosTest(desc, func) { diff --git a/jstests/sslSpecial/tls1_0.js b/jstests/sslSpecial/tls1_0.js index 699b977725d..9955421da50 100644 --- a/jstests/sslSpecial/tls1_0.js +++ b/jstests/sslSpecial/tls1_0.js @@ -47,11 +47,14 @@ function test(serverDP, clientDP, shouldSucceed) { serverOpts.sslDisabledProtocols = serverDP; } clearRawMongoProgramOutput(); - const mongod = MongoRunner.runMongod(serverOpts); - if (!mongod) { + let mongod; + try { + mongod = MongoRunner.runMongod(serverOpts); + } catch (e) { assert(!shouldSucceed); return; } + assert(mongod); let clientOpts = []; if (clientDP !== null) { diff --git a/src/mongo/shell/servers.js b/src/mongo/shell/servers.js index e33a1a386e8..76665f783e5 100644 --- a/src/mongo/shell/servers.js +++ b/src/mongo/shell/servers.js @@ -1417,14 +1417,15 @@ function appendSetParameterArgs(argArray) { /** * Continuously tries to establish a connection to the server on the specified port. * - * If a connection cannot be established within a time limit, an exception will be thrown. If - * the process for the given 'pid' is found to no longer be running, this function will - * terminate and return null. + * If a connection cannot be established within a time limit, or if the process terminated + * with a non-zero exit code, an exception will be thrown. If the process for the given + * 'pid' is found to have gracefully terminated, this function will terminate and return + * null. * * @param {int} [pid] the process id of the node to connect to. * @param {int} [port] the port of the node to connect to. * @param {int} [undoLiveRecordPid=null] the process id of the `live-record` process. - * @returns a new Mongo connection object, or null if the process is not running. + * @returns a new Mongo connection object, or null if the process gracefully terminated. */ MongoRunner.awaitConnection = function({pid, port, undoLiveRecordPid = null} = {}) { var conn = null; @@ -1443,6 +1444,9 @@ MongoRunner.awaitConnection = function({pid, port, undoLiveRecordPid = null} = { if (undoLiveRecordPid) { _stopUndoLiveRecord(undoLiveRecordPid); } + if (res.exitCode !== MongoRunner.EXIT_CLEAN) { + throw new MongoRunner.StopError(res.exitCode); + } return true; } } |