From be39a8421fcdb1d17186bc1e126074b773fcf26b Mon Sep 17 00:00:00 2001 From: Moustafa Maher Date: Tue, 22 Oct 2024 14:03:44 -0700 Subject: [PATCH] SERVER-95628 Make rawMongoProgramOutput more robust (#28204) GitOrigin-RevId: 6b01ab93e5ba70a22cc816931cd464b6f2ddbd13 --- jstests/auth/auth_pass_prompt.js | 2 +- jstests/auth/repl_require_keyfile.js | 7 ++-- jstests/disk/libs/wt_file_helper.js | 6 +-- .../repair_removes_invalid_index_options.js | 2 +- ...wt_startup_with_missing_user_collection.js | 2 +- jstests/libs/python.js | 2 +- jstests/libunwind/stacktrace_signal.js | 2 +- .../default_startup_FCV_parameter.js | 14 ++++--- ...ade_downgrade_while_creating_collection.js | 4 +- .../multiVersion/validate_cross_version.js | 2 +- .../noPassthrough/architecture/bind_ip_all.js | 2 +- .../architecture/grpc_metrics.js | 2 +- .../architecture/port_options.js | 4 +- .../architecture/quiet_mongod.js | 8 ++-- .../compression/compression_options.js | 2 +- jstests/noPassthrough/exit_logging.js | 2 +- .../hybrid_unique_index_with_updates.js | 2 +- ...dex_build_killop_secondary_after_commit.js | 4 +- ...ex_build_killop_secondary_before_commit.js | 2 +- .../index_builds_ignore_prepare_conflicts.js | 4 +- ..._awaiting_primary_abort_crash_on_commit.js | 2 +- ...index_secondary_commit_after_scan_error.js | 2 +- .../indexbg_killop_secondary_success.js | 2 +- .../index_builds/indexbg_killop_stepdown.js | 2 +- jstests/noPassthrough/js_exceptions.js | 2 +- .../noPassthrough/libs/configExpand/lib.js | 4 +- jstests/noPassthrough/libs/index_build.js | 4 +- .../libs/startup_shutdown_helpers.js | 2 +- .../lock_file/lock_file_fail_to_open.js | 2 +- .../noPassthrough/logging/startup_logging.js | 2 +- .../check_for_oplog_cap_maintainer_thread.js | 6 +-- ...plication_while_recovering_must_succeed.js | 2 +- jstests/noPassthrough/parse_zone_info.js | 6 +-- .../internal_validate_features_as_primary.js | 8 ++-- .../repl_write_threads_start_param.js | 16 ++++---- .../reproducible_initializer_order.js | 2 +- .../unknown-set-parameter.js | 6 +-- .../shell/data_consistency_checks.js | 6 ++- jstests/noPassthrough/shell/launcher_test.js | 2 +- jstests/noPassthrough/shell/quiet_shell.js | 4 +- jstests/noPassthrough/shell/shell_history.js | 2 +- .../noPassthrough/shell/shell_interactive.js | 4 +- .../validate_hook_resume_fcv_upgrade.js | 2 +- jstests/noPassthrough/version.js | 2 +- .../wt_integration/wt_operation_stats.js | 2 +- jstests/ocsp/lib/mock_ocsp.js | 2 +- jstests/ocsp/lib/ocsp_helpers.js | 2 +- jstests/ocsp/ocsp_basic.js | 2 +- .../ocsp/ocsp_client_verification_logging.js | 4 +- ...xtra_index_keys_coll_or_index_not_found.js | 2 +- .../dbcheck_extra_keys_rate_limits.js | 4 +- .../replsets/get_replication_info_helper.js | 19 +++++---- ...n_default_get_last_error_defaults_fails.js | 2 +- jstests/replsets/libs/dbcheck_utils.js | 4 +- .../libs/rollback_resumable_index_build.js | 2 +- jstests/replsets/libs/secondary_reads_test.js | 2 +- ..._replication_info_unreachable_secondary.js | 4 +- .../repl_startup_error_no_hang_on_shutdown.js | 2 +- jstests/replsets/rollback_time_limit_param.js | 2 +- ...back_unclean_shutdowns_parameter_obeyed.js | 3 +- ...tup_recovery_for_restore_needs_rollback.js | 3 +- .../startup_recovery_for_restore_restarts.js | 10 +++-- .../resmoke_selftest/shell_hang_analyzer.js | 6 +-- jstests/sharding/libs/proxy_protocol.js | 2 +- .../libs/sharded_transactions_helpers.js | 2 +- jstests/sharding/set_fcv_logging.js | 22 +++++----- jstests/sharding/shard_identity_rollback.js | 2 +- jstests/sharding/time_zone_info_mongos.js | 6 +-- ...mmit_optimizations_for_read_only_shards.js | 2 +- .../terminate_during_shutdown_checkpoint.js | 2 +- jstests/ssl/cluster_member.js | 4 +- jstests/ssl/macos_encrypted_pem.js | 2 +- jstests/ssl/repl_ssl_split_horizon.js | 4 +- jstests/ssl/shell_option_parsing.js | 2 +- jstests/ssl/ssl_alert_reporting.js | 2 +- jstests/ssl/ssl_ca_options.js | 10 ++--- jstests/ssl/ssl_cert_selector_apple.js | 4 +- .../ssl/ssl_client_bad_certificate_warning.js | 2 +- ..._client_certificate_warning_suppression.js | 6 +-- jstests/ssl/ssl_cn_with_san.js | 4 +- jstests/ssl/ssl_invalid_selector.js | 2 +- jstests/ssl/ssl_invalid_server_cert.js | 2 +- jstests/ssl/ssl_mongodb_x509.js | 3 +- jstests/ssl/x509_all_the_oids.js | 2 +- jstests/ssl/x509_startup_warning.js | 2 +- .../cluster_auth_x509_subject_attributes.js | 2 +- jstests/sslSpecial/tls1_0.js | 2 +- jstests/ssl_linear/ssl_cert_selector.js | 4 +- jstests/ssl_linear/ssl_with_system_ca.js | 2 +- src/mongo/shell/shell_utils_launcher.cpp | 41 ++++++++++++++++--- 90 files changed, 214 insertions(+), 170 deletions(-) diff --git a/jstests/auth/auth_pass_prompt.js b/jstests/auth/auth_pass_prompt.js index 07791a2056e..87a022a21f5 100644 --- a/jstests/auth/auth_pass_prompt.js +++ b/jstests/auth/auth_pass_prompt.js @@ -18,7 +18,7 @@ if (!_isWindows()) { binshell, '-c', `echo password | ${mongo} --host ${host} --port ${port} --eval ${auth}`); assert.soon(() => { - const output = rawMongoProgramOutput(); + const output = rawMongoProgramOutput("(Enter password:|Successfully authenticated)"); return output.includes("Enter password:") && output.includes("Successfully authenticated"); }); diff --git a/jstests/auth/repl_require_keyfile.js b/jstests/auth/repl_require_keyfile.js index 2ee421f2afd..530c028f2c7 100644 --- a/jstests/auth/repl_require_keyfile.js +++ b/jstests/auth/repl_require_keyfile.js @@ -9,7 +9,6 @@ assert.throws(function() { rsTest.startSet({auth: "", oplogSize: 10}); }); -const mongoOutput = rawMongoProgramOutput(); -assert(mongoOutput.indexOf( - "security.keyFile is required when authorization is enabled with replica sets") >= 0, - "Expected error message about missing keyFile on startup"); \ No newline at end of file +const subStr = "security.keyFile is required when authorization is enabled with replica sets"; +const mongoOutput = rawMongoProgramOutput(subStr); +assert(mongoOutput.indexOf(subStr) >= 0, "Expected error message about missing keyFile on startup"); \ No newline at end of file diff --git a/jstests/disk/libs/wt_file_helper.js b/jstests/disk/libs/wt_file_helper.js index 1be5387be65..77e5d97d55a 100644 --- a/jstests/disk/libs/wt_file_helper.js +++ b/jstests/disk/libs/wt_file_helper.js @@ -106,7 +106,7 @@ export let assertErrorOnStartupWhenStartingAsReplSet = function(dbpath, port, rs let node = MongoRunner.runMongod( {dbpath: dbpath, port: port, replSet: rsName, noCleanData: true, waitForConnect: false}); assert.soon(function() { - return rawMongoProgramOutput().search(/Fatal assertion.*50923/) >= 0; + return rawMongoProgramOutput("Fatal assertion").search(/50923/) >= 0; }); MongoRunner.stopMongod(node, null, {allowedExitCode: MongoRunner.EXIT_ABRUPT}); }; @@ -122,7 +122,7 @@ export let assertErrorOnStartupAfterIncompleteRepair = function(dbpath, port) { let node = MongoRunner.runMongod( {dbpath: dbpath, port: port, noCleanData: true, waitForConnect: false}); assert.soon(function() { - return rawMongoProgramOutput().search(/Fatal assertion.*50922/) >= 0; + return rawMongoProgramOutput("Fatal assertion").search(/50922/) >= 0; }); MongoRunner.stopMongod(node, null, {allowedExitCode: MongoRunner.EXIT_ABRUPT}); }; @@ -151,7 +151,7 @@ export let assertErrorOnStartupWhenInitialSyncingWithData = function(replSet, or jsTestLog("Ignoring exception from replsettest.start: " + tojson(e)); } finally { assert.soon(function() { - return rawMongoProgramOutput().search(/Fatal assertion.*9184100/) >= 0; + return rawMongoProgramOutput("Fatal assertion").search(/9184100/) >= 0; }); if (node) { MongoRunner.stopMongod(node, null, {allowedExitCode: MongoRunner.EXIT_ABRUPT}); diff --git a/jstests/disk/repair_removes_invalid_index_options.js b/jstests/disk/repair_removes_invalid_index_options.js index 32b75494fa2..6f978c7632e 100644 --- a/jstests/disk/repair_removes_invalid_index_options.js +++ b/jstests/disk/repair_removes_invalid_index_options.js @@ -51,7 +51,7 @@ let port; startMongodOnExistingPath(dbPath); }); - assert(rawMongoProgramOutput().match("Fatal assertion.*28782"), + assert(rawMongoProgramOutput("Fatal assertion").match("28782"), "Mongod should have aborted due to an invalid index descriptor."); jsTestLog("Exiting restartAndVerifyMongodCrashes."); })(); diff --git a/jstests/disk/wt_startup_with_missing_user_collection.js b/jstests/disk/wt_startup_with_missing_user_collection.js index b001c275dc9..e1df5403bc0 100644 --- a/jstests/disk/wt_startup_with_missing_user_collection.js +++ b/jstests/disk/wt_startup_with_missing_user_collection.js @@ -67,7 +67,7 @@ testDB = mongod.getDB(dbName); assert.throws(() => { assert.commandWorked(testDB.getCollection("a").insert({})); }); -assert.gte(rawMongoProgramOutput().search("Fatal assertion.*50883"), 0); +assert.gte(rawMongoProgramOutput("Fatal assertion").search("50883"), 0); // Perform a startup, drop collection "a" and shutdown. mongod = startMongodOnExistingPath(dbpath); diff --git a/jstests/libs/python.js b/jstests/libs/python.js index ff390dcc731..dbc7c79cbc0 100644 --- a/jstests/libs/python.js +++ b/jstests/libs/python.js @@ -5,7 +5,7 @@ export function getPython3Binary() { // or else we will pick up a python that is not in our venv clearRawMongoProgramOutput(); assert.eq(runNonMongoProgram("python", "--version"), 0); - const pythonVersion = rawMongoProgramOutput(); // Will look like "Python 3.10.4\n" + const pythonVersion = rawMongoProgramOutput("Python"); // Will look like "Python 3.10.4\n" const usingPython310 = /Python 3\.10/.exec(pythonVersion); if (usingPython310) { print( diff --git a/jstests/libunwind/stacktrace_signal.js b/jstests/libunwind/stacktrace_signal.js index 846a2297628..ecd25131a89 100644 --- a/jstests/libunwind/stacktrace_signal.js +++ b/jstests/libunwind/stacktrace_signal.js @@ -11,7 +11,7 @@ const conn = MongoRunner.runMongod(); // convert the float to a string to make sure it's correctly represented. runNonMongoProgram('/bin/kill', '-s', 'SIGUSR2', conn.pid.valueOf().toString()); MongoRunner.stopMongod(conn); -const output = rawMongoProgramOutput(); +const output = rawMongoProgramOutput("(processInfo|backtrace)"); assert(output.search(/"processInfo":/) >= 0, output); // Will be several of these assert(output.search(/"backtrace":/) >= 0, output); diff --git a/jstests/multiVersion/genericSetFCVUsage/default_startup_FCV_parameter.js b/jstests/multiVersion/genericSetFCVUsage/default_startup_FCV_parameter.js index 6b0bcb55963..14716d2a603 100644 --- a/jstests/multiVersion/genericSetFCVUsage/default_startup_FCV_parameter.js +++ b/jstests/multiVersion/genericSetFCVUsage/default_startup_FCV_parameter.js @@ -45,7 +45,7 @@ function runStandaloneTest() { adminDB = conn.getDB("admin"); // The FCV should still be the original FCV, not the provided defaultStartupFCV. checkFCV(adminDB, lastContinuousFCV); - assert(rawMongoProgramOutput().includes( + assert(rawMongoProgramOutput(".*").includes( "Ignoring the provided defaultStartupFCV parameter since the FCV already exists")); MongoRunner.stopMongod(conn); @@ -63,7 +63,8 @@ function runStandaloneTest() { assert.neq(null, conn); adminDB = conn.getDB("admin"); checkFCV(adminDB, latestFCV); - assert(rawMongoProgramOutput().includes("The provided 'defaultStartupFCV' is not a valid FCV")); + assert(rawMongoProgramOutput(".*").includes( + "The provided 'defaultStartupFCV' is not a valid FCV")); MongoRunner.stopMongod(conn); clearRawMongoProgramOutput(); @@ -72,7 +73,8 @@ function runStandaloneTest() { assert.neq(null, conn); adminDB = conn.getDB("admin"); checkFCV(adminDB, latestFCV); - assert(rawMongoProgramOutput().includes("The provided 'defaultStartupFCV' is not a valid FCV")); + assert(rawMongoProgramOutput(".*").includes( + "The provided 'defaultStartupFCV' is not a valid FCV")); MongoRunner.stopMongod(conn); } @@ -166,7 +168,8 @@ function runReplicaSetTest() { secondaryAdminDB = rst.getSecondary().getDB("admin"); checkFCV(primaryAdminDB, latestFCV); checkFCV(secondaryAdminDB, latestFCV); - assert(rawMongoProgramOutput().includes("The provided 'defaultStartupFCV' is not a valid FCV")); + assert(rawMongoProgramOutput(".*").includes( + "The provided 'defaultStartupFCV' is not a valid FCV")); rst.stopSet(); clearRawMongoProgramOutput(); @@ -180,7 +183,8 @@ function runReplicaSetTest() { secondaryAdminDB = rst.getSecondary().getDB("admin"); checkFCV(primaryAdminDB, latestFCV); checkFCV(secondaryAdminDB, latestFCV); - assert(rawMongoProgramOutput().includes("The provided 'defaultStartupFCV' is not a valid FCV")); + assert(rawMongoProgramOutput(".*").includes( + "The provided 'defaultStartupFCV' is not a valid FCV")); rst.stopSet(); } diff --git a/jstests/multiVersion/genericSetFCVUsage/upgrade_downgrade_while_creating_collection.js b/jstests/multiVersion/genericSetFCVUsage/upgrade_downgrade_while_creating_collection.js index 57c3955fbdf..264232b26db 100644 --- a/jstests/multiVersion/genericSetFCVUsage/upgrade_downgrade_while_creating_collection.js +++ b/jstests/multiVersion/genericSetFCVUsage/upgrade_downgrade_while_creating_collection.js @@ -40,8 +40,8 @@ function runTest(downgradeFCV) { }, primary.port); assert.soon(function() { - return rawMongoProgramOutput().match( - /\"id\":20320.*test.mycoll/); // Create Collection log + return rawMongoProgramOutput("\"id\":20320") + .match(/\"id\":20320.*test.mycoll/); // Create Collection log }); awaitUpgradeFCV = startParallelShell( diff --git a/jstests/multiVersion/validate_cross_version.js b/jstests/multiVersion/validate_cross_version.js index ee58d7c292e..584506d21f4 100644 --- a/jstests/multiVersion/validate_cross_version.js +++ b/jstests/multiVersion/validate_cross_version.js @@ -56,7 +56,7 @@ function testVersion(binVersion, fcv, shouldCorrupt) { MongoRunner.runMongod({port: port, dbpath: dbpath, validate: "", noCleanData: true}); - let validateLogs = rawMongoProgramOutput() + let validateLogs = rawMongoProgramOutput("(9437301|9437303|9437304)") .split("\n") .filter(line => line.trim() !== "") .map(line => JSON.parse(line.split("|").slice(1).join("|"))); diff --git a/jstests/noPassthrough/architecture/bind_ip_all.js b/jstests/noPassthrough/architecture/bind_ip_all.js index 06e5ec6c29c..d00fef1f13d 100644 --- a/jstests/noPassthrough/architecture/bind_ip_all.js +++ b/jstests/noPassthrough/architecture/bind_ip_all.js @@ -9,7 +9,7 @@ function runTest(config, opt, expectStar, expectLocalhost) { const mongod = runMongoProgram('mongod', '--port', port, '--config', config, opt, '--outputConfig'); assert.eq(mongod, 0); - const output = rawMongoProgramOutput(); + const output = rawMongoProgramOutput("bindIp"); assert.eq(output.search(/bindIp: "\*"/) >= 0, expectStar, output); assert.eq(output.search(/bindIp: localhost/) >= 0, expectLocalhost, output); assert.eq(output.search(/bindIpAll:/) >= 0, false, output); diff --git a/jstests/noPassthrough/architecture/grpc_metrics.js b/jstests/noPassthrough/architecture/grpc_metrics.js index 106c9c72d48..6fab9d023dd 100644 --- a/jstests/noPassthrough/architecture/grpc_metrics.js +++ b/jstests/noPassthrough/architecture/grpc_metrics.js @@ -120,7 +120,7 @@ function runTest(conn) { evalCmd(uri, `print("Kill Test\\n"); sleep(${kShellShutdownDelay});`, false, function(pid) { // Wait for the output from the eval string so that we know prefix ops have completed, // then kill the shell so that the stream shuts down unsuccessfully. - assert.soon(() => rawMongoProgramOutput().includes("Kill Test"), + assert.soon(() => rawMongoProgramOutput("Kill Test").includes("Kill Test"), "Shell start failure", kShellStartTimeout, kShellStartInterval); diff --git a/jstests/noPassthrough/architecture/port_options.js b/jstests/noPassthrough/architecture/port_options.js index 159eb409ed6..3b364471235 100644 --- a/jstests/noPassthrough/architecture/port_options.js +++ b/jstests/noPassthrough/architecture/port_options.js @@ -16,7 +16,7 @@ function runTest(bindIP, expectOk) { // We use assert.soonNoExcept() here because the mongod may not be logging yet. assert.soonNoExcept(() => { - const logContents = rawMongoProgramOutput(); + const logContents = rawMongoProgramOutput("\"id\":(7401305|23016)"); let found; if (jsTestOptions().shellGRPC) { found = logContents.match( @@ -47,7 +47,7 @@ function runTest(bindIP, expectOk) { const ec = waitProgram(pid); assert.eq(ec, MongoRunner.EXIT_NET_ERROR); assert.soonNoExcept(() => { - const logContents = rawMongoProgramOutput(); + const logContents = rawMongoProgramOutput("ephemeral port"); const found = logContents.match( /Port 0 \(ephemeral port\) is not allowed when listening on multiple IP interfaces/); return (found !== null); diff --git a/jstests/noPassthrough/architecture/quiet_mongod.js b/jstests/noPassthrough/architecture/quiet_mongod.js index 5d3e52bd212..f2ef482a021 100644 --- a/jstests/noPassthrough/architecture/quiet_mongod.js +++ b/jstests/noPassthrough/architecture/quiet_mongod.js @@ -16,10 +16,10 @@ const clientMetadataLogLineRegex = /\"NETWORK.+51800.+client metadata\"/; // Issue a command and wait for a log line acknowledging it to be sure any client metadata log // lines have been flushed. conn.getDB(dbName).runCommand({ping: 1}); - assert.soon(() => rawMongoProgramOutput().match(firstCommandLogLineRegex), + assert.soon(() => rawMongoProgramOutput(".*").match(firstCommandLogLineRegex), "did not see log line acknowledging first command"); - const mongoOutput = rawMongoProgramOutput(); + const mongoOutput = rawMongoProgramOutput(".*"); assert.gte(mongoOutput.match(clientMetadataLogLineRegex).length, 1, "did not see client metadata log line while not in quiet mode"); @@ -35,10 +35,10 @@ const clientMetadataLogLineRegex = /\"NETWORK.+51800.+client metadata\"/; // Issue a command and wait for a log line acknowledging it to be sure any client metadata log // lines have been flushed. conn.getDB(dbName).runCommand({ping: 1}); - assert.soon(() => rawMongoProgramOutput().match(firstCommandLogLineRegex), + assert.soon(() => rawMongoProgramOutput(".*").match(firstCommandLogLineRegex), "did not see log line acknowledging first command"); - const mongoOutput = rawMongoProgramOutput(); + const mongoOutput = rawMongoProgramOutput(".*"); assert.eq(mongoOutput.match(clientMetadataLogLineRegex), null, "saw client metadata log line while in quiet mode"); diff --git a/jstests/noPassthrough/compression/compression_options.js b/jstests/noPassthrough/compression/compression_options.js index 7d69a1e41cd..3fe16d4c5a5 100644 --- a/jstests/noPassthrough/compression/compression_options.js +++ b/jstests/noPassthrough/compression/compression_options.js @@ -14,7 +14,7 @@ var runTest = function(optionValue, expected) { "--networkMessageCompressors=snappy"), 0); - var output = rawMongoProgramOutput() + var output = rawMongoProgramOutput(".*") .split("\n") .map(function(str) { str = str.replace(/^sh[0-9]+\| /, ""); diff --git a/jstests/noPassthrough/exit_logging.js b/jstests/noPassthrough/exit_logging.js index 62e44898571..629ceca1391 100644 --- a/jstests/noPassthrough/exit_logging.js +++ b/jstests/noPassthrough/exit_logging.js @@ -28,7 +28,7 @@ function testShutdownLogging(launcher, crashFn, matchFn, expectedExitCode) { var conn = launcher.start({}); function checkOutput() { - var logContents = rawMongoProgramOutput(); + var logContents = rawMongoProgramOutput(".*"); function printLog() { // We can't just return a string because it will be well over the max // line length. diff --git a/jstests/noPassthrough/index_builds/hybrid_unique_index_with_updates.js b/jstests/noPassthrough/index_builds/hybrid_unique_index_with_updates.js index 62502cd3ff1..2a2693fb932 100644 --- a/jstests/noPassthrough/index_builds/hybrid_unique_index_with_updates.js +++ b/jstests/noPassthrough/index_builds/hybrid_unique_index_with_updates.js @@ -29,7 +29,7 @@ let doDuringFailpoint = function( hitFailpointFunc(); - assert.soon(() => structuredLogRegEx.test(rawMongoProgramOutput())); + assert.soon(() => structuredLogRegEx.test(rawMongoProgramOutput(".*"))); duringFailpointFunc(); diff --git a/jstests/noPassthrough/index_builds/index_build_killop_secondary_after_commit.js b/jstests/noPassthrough/index_builds/index_build_killop_secondary_after_commit.js index 8225acfe998..cf7532254a3 100644 --- a/jstests/noPassthrough/index_builds/index_build_killop_secondary_after_commit.js +++ b/jstests/noPassthrough/index_builds/index_build_killop_secondary_after_commit.js @@ -70,14 +70,14 @@ const gracefulIndexBuildFlag = FeatureFlagUtil.isEnabled(testDB, "IndexBuildGrac if (!gracefulIndexBuildFlag) { // We expect this to crash the secondary because this error is not recoverable assert.soon(function() { - return rawMongoProgramOutput().search(/Fatal assertion.*(51101)/) >= 0; + return rawMongoProgramOutput(".*").search(/Fatal assertion.*(51101)/) >= 0; }); } else { // Expect the secondary to crash. Depending on timing, this can be either because the secondary // was waiting for a primary abort when a 'commitIndexBuild' is applied, or because the build // fails and tries to request an abort while a 'commitIndexBuild' is being applied. assert.soon(function() { - return rawMongoProgramOutput().search(/Fatal assertion.*(7329403|7329407)/) >= 0; + return rawMongoProgramOutput(".*").search(/Fatal assertion.*(7329403|7329407)/) >= 0; }); } diff --git a/jstests/noPassthrough/index_builds/index_build_killop_secondary_before_commit.js b/jstests/noPassthrough/index_builds/index_build_killop_secondary_before_commit.js index db8b5fcede4..6fe691d98d0 100644 --- a/jstests/noPassthrough/index_builds/index_build_killop_secondary_before_commit.js +++ b/jstests/noPassthrough/index_builds/index_build_killop_secondary_before_commit.js @@ -75,7 +75,7 @@ function killopIndexBuildOnSecondaryOnFailpoint(rst, failpointName, shouldSuccee } else { // We expect this to crash the secondary because this error is not recoverable. assert.soon(function() { - return rawMongoProgramOutput().search(/Fatal assertion.*(51101)/) >= 0; + return rawMongoProgramOutput(".*").search(/Fatal assertion.*(51101)/) >= 0; }); // After restarting the secondary, expect that the index build completes successfully. diff --git a/jstests/noPassthrough/index_builds/index_builds_ignore_prepare_conflicts.js b/jstests/noPassthrough/index_builds/index_builds_ignore_prepare_conflicts.js index c98e915db36..3dc2206a106 100644 --- a/jstests/noPassthrough/index_builds/index_builds_ignore_prepare_conflicts.js +++ b/jstests/noPassthrough/index_builds/index_builds_ignore_prepare_conflicts.js @@ -77,8 +77,8 @@ let runTest = function(conn) { // Unpause the index build from the first failpoint so that it can resume and pause at the // next failpoint. IndexBuildTest.resumeIndexBuilds(conn); - assert.soon(() => - rawMongoProgramOutput().indexOf("Hanging after index build first drain") >= 0); + assert.soon( + () => rawMongoProgramOutput(".*").indexOf("Hanging after index build first drain") >= 0); // Right before the index build completes, ensure no prepare conflicts were hit. IndexBuildTest.assertIndexBuildCurrentOpContents(testDB, opId, (op) => { diff --git a/jstests/noPassthrough/index_builds/index_secondary_awaiting_primary_abort_crash_on_commit.js b/jstests/noPassthrough/index_builds/index_secondary_awaiting_primary_abort_crash_on_commit.js index 0b547a93d17..129e37aee30 100644 --- a/jstests/noPassthrough/index_builds/index_secondary_awaiting_primary_abort_crash_on_commit.js +++ b/jstests/noPassthrough/index_builds/index_secondary_awaiting_primary_abort_crash_on_commit.js @@ -87,7 +87,7 @@ assert.eq(MongoRunner.EXIT_ABORT, res.exitCode); // Expect the secondary to crash. Depending on timing, this can be either because the secondary was // waiting for a primary abort when a 'commitIndexBuild' is applied, or because the build fails and // tries to request an abort while a 'commitIndexBuild' is being applied. -assert(rawMongoProgramOutput().match('Fatal assertion.*(7329403|7329407)'), +assert(rawMongoProgramOutput(".*").match('Fatal assertion.*(7329403|7329407)'), 'Receiving a commit from the primary for a failing index build should crash the secondary'); createIdx(); diff --git a/jstests/noPassthrough/index_builds/index_secondary_commit_after_scan_error.js b/jstests/noPassthrough/index_builds/index_secondary_commit_after_scan_error.js index 525765dca29..5f852c9037f 100644 --- a/jstests/noPassthrough/index_builds/index_secondary_commit_after_scan_error.js +++ b/jstests/noPassthrough/index_builds/index_secondary_commit_after_scan_error.js @@ -77,7 +77,7 @@ assert.soon(function() { // Secondary should crash on receiving the unexpected commitIndexBuild oplog entry. assert.eq(MongoRunner.EXIT_ABORT, res.exitCode); -assert(rawMongoProgramOutput().match('Fatal assertion.*4698902'), +assert(rawMongoProgramOutput(".*").match('Fatal assertion.*4698902'), 'Index build should have aborted secondary due to unexpected commitIndexBuild oplog entry.'); // Check indexes on primary. diff --git a/jstests/noPassthrough/index_builds/indexbg_killop_secondary_success.js b/jstests/noPassthrough/index_builds/indexbg_killop_secondary_success.js index 3c6cdd74c2d..02d6486c008 100644 --- a/jstests/noPassthrough/index_builds/indexbg_killop_secondary_success.js +++ b/jstests/noPassthrough/index_builds/indexbg_killop_secondary_success.js @@ -73,7 +73,7 @@ assert.commandWorked(secondaryDB.killOp(opId)); if (!gracefulIndexBuildFlag) { // We expect this to crash the secondary because this error is not recoverable assert.soon(function() { - return rawMongoProgramOutput().search(/Fatal assertion.*(51101)/) >= 0; + return rawMongoProgramOutput(".*").search(/Fatal assertion.*(51101)/) >= 0; }); // After restarting the secondary, expect that the index build completes successfully. diff --git a/jstests/noPassthrough/index_builds/indexbg_killop_stepdown.js b/jstests/noPassthrough/index_builds/indexbg_killop_stepdown.js index 9e6afaefb54..e1e944cf0a7 100644 --- a/jstests/noPassthrough/index_builds/indexbg_killop_stepdown.js +++ b/jstests/noPassthrough/index_builds/indexbg_killop_stepdown.js @@ -75,7 +75,7 @@ const gracefulIndexBuildFlag = FeatureFlagUtil.isEnabled(testDB, "IndexBuildGrac if (!gracefulIndexBuildFlag) { // We expect the node to crash without this feature enabled. assert.soon(function() { - return rawMongoProgramOutput().search(/Fatal assertion.*51101/) >= 0; + return rawMongoProgramOutput(".*").search(/Fatal assertion.*51101/) >= 0; }); // After restarting the old primary, we expect that the index build completes successfully. diff --git a/jstests/noPassthrough/js_exceptions.js b/jstests/noPassthrough/js_exceptions.js index a4f5773f8a5..95421843911 100644 --- a/jstests/noPassthrough/js_exceptions.js +++ b/jstests/noPassthrough/js_exceptions.js @@ -85,7 +85,7 @@ tests.forEach(function(t) { clearRawMongoProgramOutput(); assert.throws(startParallelShell( code + ";\nrecurser(0," + depth + "," + tojson(t.callback) + ");", false, true)); - let output = rawMongoProgramOutput(); + let output = rawMongoProgramOutput(".*"); let lines = output.split(/\s*\n|\\n/); let matchShellExp = false; while (lines.length > 0 & matchShellExp !== true) { diff --git a/jstests/noPassthrough/libs/configExpand/lib.js b/jstests/noPassthrough/libs/configExpand/lib.js index 0e6f171a295..dc96c0d9b1a 100644 --- a/jstests/noPassthrough/libs/configExpand/lib.js +++ b/jstests/noPassthrough/libs/configExpand/lib.js @@ -68,7 +68,7 @@ export class ConfigExpandRestServer { // Wait for the web server to start assert.soon(function() { - return rawMongoProgramOutput().search("Mock Web Server Listening") !== -1; + return rawMongoProgramOutput(".*").search("Mock Web Server Listening") !== -1; }); print("Mock HTTP Server sucessfully started."); @@ -194,7 +194,7 @@ export function configExpandFailure(config, test = null, opts = {}) { const mongod = _startMongoProgram({args: args}); assert.soon(function() { - return rawMongoProgramOutput().match(test); + return rawMongoProgramOutput(".*").match(test); }); if (mongod) { stopMongoProgramByPid(mongod); diff --git a/jstests/noPassthrough/libs/index_build.js b/jstests/noPassthrough/libs/index_build.js index 7d745ae396f..56d0e8dfbf4 100644 --- a/jstests/noPassthrough/libs/index_build.js +++ b/jstests/noPassthrough/libs/index_build.js @@ -566,7 +566,7 @@ export const ResumableIndexBuildTest = class { // Ensure that the resumable index build state was written to disk upon clean shutdown. for (const buildUUID of buildUUIDs) { - assert(RegExp("4841502.*" + buildUUID).test(rawMongoProgramOutput())); + assert(RegExp("4841502.*" + buildUUID).test(rawMongoProgramOutput(".*"))); } if (runBeforeStartup) @@ -833,7 +833,7 @@ export const ResumableIndexBuildTest = class { clearRawMongoProgramOutput(); rst.stop(resumeNode); - assert(RegExp("4841502.*" + buildUUID).test(rawMongoProgramOutput())); + assert(RegExp("4841502.*" + buildUUID).test(rawMongoProgramOutput(".*"))); rst.start(resumeNode, {noCleanData: true}); otherNodeFp.off(); diff --git a/jstests/noPassthrough/libs/startup_shutdown_helpers.js b/jstests/noPassthrough/libs/startup_shutdown_helpers.js index 5eac93da34c..2523f45f487 100644 --- a/jstests/noPassthrough/libs/startup_shutdown_helpers.js +++ b/jstests/noPassthrough/libs/startup_shutdown_helpers.js @@ -123,7 +123,7 @@ function forkThenShutdownMongoProgram(program, args) { clearRawMongoProgramOutput(); assert.eq(0, runMongoProgram.apply(this, arrOpts)); - const rawOutput = rawMongoProgramOutput(); + const rawOutput = rawMongoProgramOutput(".*"); const pid = getPidFromRawProgramOutput(rawOutput); assert.neq(null, pid, "Failed to parse forked process pid"); diff --git a/jstests/noPassthrough/lock_file/lock_file_fail_to_open.js b/jstests/noPassthrough/lock_file/lock_file_fail_to_open.js index 2b59bc34c89..200d0267277 100644 --- a/jstests/noPassthrough/lock_file/lock_file_fail_to_open.js +++ b/jstests/noPassthrough/lock_file/lock_file_fail_to_open.js @@ -12,7 +12,7 @@ clearRawMongoProgramOutput(); // dbpath. assert.throws(() => MongoRunner.runMongod({dbpath: dbPath, noCleanData: true})); -var logContents = rawMongoProgramOutput(); +var logContents = rawMongoProgramOutput(".*"); assert(logContents.indexOf("Unable to lock the lock file") > 0 || // Windows error message is different. logContents.indexOf("Unable to create/open the lock file") > 0); diff --git a/jstests/noPassthrough/logging/startup_logging.js b/jstests/noPassthrough/logging/startup_logging.js index a0f870c8872..d562a023748 100644 --- a/jstests/noPassthrough/logging/startup_logging.js +++ b/jstests/noPassthrough/logging/startup_logging.js @@ -9,7 +9,7 @@ function makeRegExMatchFn(pattern) { } function testStartupLogging(launcher, matchFn, expectedExitCode) { - assert(matchFn(rawMongoProgramOutput())); + assert(matchFn(rawMongoProgramOutput(".*"))); } function validateWaitingMessage(launcher) { diff --git a/jstests/noPassthrough/oplog/check_for_oplog_cap_maintainer_thread.js b/jstests/noPassthrough/oplog/check_for_oplog_cap_maintainer_thread.js index 6c43f6862d1..9619ebb4841 100644 --- a/jstests/noPassthrough/oplog/check_for_oplog_cap_maintainer_thread.js +++ b/jstests/noPassthrough/oplog/check_for_oplog_cap_maintainer_thread.js @@ -43,7 +43,7 @@ let conn = MongoRunner.runMongod({ }); assert(conn); MongoRunner.stopMongod(conn); -verifyOplogCapMaintainerThreadNotStarted(rawMongoProgramOutput()); +verifyOplogCapMaintainerThreadNotStarted(rawMongoProgramOutput(".*")); jsTestLog("Testing recoverFromOplogAsStandalone mode"); clearRawMongoProgramOutput(); @@ -54,7 +54,7 @@ conn = MongoRunner.runMongod({ }); assert(conn); MongoRunner.stopMongod(conn); -verifyOplogCapMaintainerThreadNotStarted(rawMongoProgramOutput()); +verifyOplogCapMaintainerThreadNotStarted(rawMongoProgramOutput(".*")); jsTestLog("Testing repair mode"); clearRawMongoProgramOutput(); @@ -65,4 +65,4 @@ conn = MongoRunner.runMongod({ setParameter: {logComponentVerbosity: tojson({storage: 1})}, }); assert(!conn); -verifyOplogCapMaintainerThreadNotStarted(rawMongoProgramOutput()); \ No newline at end of file +verifyOplogCapMaintainerThreadNotStarted(rawMongoProgramOutput(".*")); \ No newline at end of file diff --git a/jstests/noPassthrough/oplog/oplog_application_while_recovering_must_succeed.js b/jstests/noPassthrough/oplog/oplog_application_while_recovering_must_succeed.js index d3986ee6c82..8a8f77ccf2c 100644 --- a/jstests/noPassthrough/oplog/oplog_application_while_recovering_must_succeed.js +++ b/jstests/noPassthrough/oplog/oplog_application_while_recovering_must_succeed.js @@ -108,7 +108,7 @@ function runTest(op, result) { assert.eq(exitCode, MongoRunner.EXIT_ABORT); assert.soon( function() { - return rawMongoProgramOutput().search(/Fatal assertion.*5415000/) >= 0; + return rawMongoProgramOutput("Fatal assertion").search(/5415000/) >= 0; }, "Node should have fasserted upon encountering a fatal error during startup", ReplSetTest.kDefaultTimeoutMS); diff --git a/jstests/noPassthrough/parse_zone_info.js b/jstests/noPassthrough/parse_zone_info.js index e4f5053bd21..ada37b35228 100644 --- a/jstests/noPassthrough/parse_zone_info.js +++ b/jstests/noPassthrough/parse_zone_info.js @@ -4,7 +4,7 @@ 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/)); +assert.neq(-1, rawMongoProgramOutput(".*").search(/Fatal assertion.*40475/)); // Test that a non-existent directory causes startup to fail. assert.throws( @@ -13,8 +13,8 @@ assert.throws( "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")); +assert(rawMongoProgramOutput(".*").includes("Error creating service context") || + rawMongoProgramOutput(".*").includes("Failed to create service context")); function testWithGoodTimeZoneDir(tz_good_path) { let conn = MongoRunner.runMongod({timeZoneInfo: tz_good_path}); diff --git a/jstests/noPassthrough/replication/internal_validate_features_as_primary.js b/jstests/noPassthrough/replication/internal_validate_features_as_primary.js index 00931fba4dc..aab0e16b408 100644 --- a/jstests/noPassthrough/replication/internal_validate_features_as_primary.js +++ b/jstests/noPassthrough/replication/internal_validate_features_as_primary.js @@ -22,8 +22,8 @@ assert.eq(res.internalValidateFeaturesAsMaster, false); let joinShell = startParallelShell( "db.adminCommand({getParameter: 1, internalValidateFeaturesAsMaster: 1});", conn.port); joinShell(); -assert(rawMongoProgramOutput().match( - "\"Use of deprecated server parameter name\",\"attr\":{\"deprecatedName\":\"internalValidateFeaturesAsMaster\"")); +assert(rawMongoProgramOutput("Use of deprecated server parameter name") + .match("\"attr\":{\"deprecatedName\":\"internalValidateFeaturesAsMaster\"")); MongoRunner.stopMongod(conn); // internalValidateFeaturesAsMaster can be set via startup parameter. @@ -59,7 +59,7 @@ joinShell = startParallelShell(() => { {replSet: "replSetName", setParameter: "internalValidateFeaturesAsPrimary=0"})); }, conn.port); joinShell(); -let joinShellOutput = rawMongoProgramOutput(); +let joinShellOutput = rawMongoProgramOutput("Cannot specify both .* and replication.replSet"); assert(joinShellOutput.match( "Cannot specify both internalValidateFeaturesAsPrimary and replication.replSet")); assert(!joinShellOutput.match( @@ -72,7 +72,7 @@ joinShell = startParallelShell(() => { {replSet: "replSetName", setParameter: "internalValidateFeaturesAsMaster=0"})); }, conn.port); joinShell(); -joinShellOutput = rawMongoProgramOutput(); +joinShellOutput = rawMongoProgramOutput("Cannot specify both .* and replication.replSet"); assert(joinShellOutput.match( "Cannot specify both internalValidateFeaturesAsMaster and replication.replSet")); assert(!joinShellOutput.match( diff --git a/jstests/noPassthrough/replication/repl_write_threads_start_param.js b/jstests/noPassthrough/replication/repl_write_threads_start_param.js index 4012ef948be..2116b52fb7c 100644 --- a/jstests/noPassthrough/replication/repl_write_threads_start_param.js +++ b/jstests/noPassthrough/replication/repl_write_threads_start_param.js @@ -7,24 +7,22 @@ // too low a count clearRawMongoProgramOutput(); 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"); +assert(rawMongoProgramOutput("Invalid value for parameter replWriterThreadCount: ") + .match("0 is not greater than or equal to 1"), + "mongod started with too low a value for replWriterThreadCount"); // too high a count clearRawMongoProgramOutput(); 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"); +assert(rawMongoProgramOutput("Invalid value for parameter replWriterThreadCount: ") + .match("257 is not less than or equal to 256"), + "mongod started with too high a value for replWriterThreadCount"); // proper count clearRawMongoProgramOutput(); 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"), +assert(rawMongoProgramOutput("Invalid value for parameter replWriterThreadCount").length == 0, "despite accepting the replWriterThreadCount value, mongod logged an error"); // getParameter to confirm the value was set diff --git a/jstests/noPassthrough/reproducible_initializer_order.js b/jstests/noPassthrough/reproducible_initializer_order.js index d418d30a998..12a5979a96d 100644 --- a/jstests/noPassthrough/reproducible_initializer_order.js +++ b/jstests/noPassthrough/reproducible_initializer_order.js @@ -8,7 +8,7 @@ const regexMatch = /\{.+"id":4777800.+"nodes":\[(.+)\].+\}/; const getInitializerOrderForSeed = (seed) => { clearRawMongoProgramOutput(); const conn = MongoRunner.runMongod({verbose: 2, initializerShuffleSeed: seed}); - const logContents = rawMongoProgramOutput(); + const logContents = rawMongoProgramOutput(".*"); const match = logContents.match(regexMatch); assert(match.length > 0); MongoRunner.stopMongod(conn); diff --git a/jstests/noPassthrough/server_parameters/unknown-set-parameter.js b/jstests/noPassthrough/server_parameters/unknown-set-parameter.js index befae23314d..8c951e6221c 100644 --- a/jstests/noPassthrough/server_parameters/unknown-set-parameter.js +++ b/jstests/noPassthrough/server_parameters/unknown-set-parameter.js @@ -17,21 +17,21 @@ function tryRun(arg) { clearRawMongoProgramOutput(); const valid = tryRun('enableTestCommands=1'); assert.eq(valid, 0); -const validOutput = rawMongoProgramOutput(); +const validOutput = rawMongoProgramOutput(".*"); assert.gte(validOutput.search(/enableTestCommands: 1/), 0, validOutput); // Negative case, invalid setparam. clearRawMongoProgramOutput(); const foo = tryRun('foo=bar'); assert.neq(foo, 0); -const fooOutput = rawMongoProgramOutput(); +const fooOutput = rawMongoProgramOutput(".*"); assert.gte(fooOutput.search(/Unknown --setParameter 'foo'/), 0, fooOutput); // Negative case, valid but unavailable setparam. clearRawMongoProgramOutput(); const graph = tryRun('roleGraphInvalidationIsFatal=true'); assert.neq(graph, 0); -const graphOutput = rawMongoProgramOutput(); +const graphOutput = rawMongoProgramOutput(".*"); assert.gte( graphOutput.search( /--setParameter 'roleGraphInvalidationIsFatal' only available when used with 'enableTestCommands'/), diff --git a/jstests/noPassthrough/shell/data_consistency_checks.js b/jstests/noPassthrough/shell/data_consistency_checks.js index 4868dd2f822..0794666dd2d 100644 --- a/jstests/noPassthrough/shell/data_consistency_checks.js +++ b/jstests/noPassthrough/shell/data_consistency_checks.js @@ -16,6 +16,10 @@ import {ShardingTest} from "jstests/libs/shardingtest.js"; TestData.skipCollectionAndIndexValidation = true; TestData.skipCheckDBHashes = true; +function regexForValidateAndDBHashSlowQuery() { + return String('Slow query.*"command":\\{"(validate|db[Hh]ash)'); +} + function makePatternForDBHash(dbName) { return new RegExp( `Slow query.*"ns":"${dbName}\\.\\$cmd".*"appName":"MongoDB Shell","command":{"db[Hh]ash`, @@ -55,7 +59,7 @@ function runDataConsistencyChecks(testCase) { // will return all of their output. testCase.teardown(); - return rawMongoProgramOutput(); + return rawMongoProgramOutput(regexForValidateAndDBHashSlowQuery()); } (function testReplicaSetWithVotingSecondaries() { diff --git a/jstests/noPassthrough/shell/launcher_test.js b/jstests/noPassthrough/shell/launcher_test.js index 95da05b5671..6cc26ca3d26 100644 --- a/jstests/noPassthrough/shell/launcher_test.js +++ b/jstests/noPassthrough/shell/launcher_test.js @@ -11,7 +11,7 @@ var echoTest = function() { // This will produce `numLines` + 1 lines of output because echo isn't being called with // `-n`. This will block until the program exits. var exitCode = runProgram("echo", lineContents); - var output = rawMongoProgramOutput(); + var output = rawMongoProgramOutput(".*"); assert.eq(0, exitCode); diff --git a/jstests/noPassthrough/shell/quiet_shell.js b/jstests/noPassthrough/shell/quiet_shell.js index 4fdde618df6..50829f53bb4 100644 --- a/jstests/noPassthrough/shell/quiet_shell.js +++ b/jstests/noPassthrough/shell/quiet_shell.js @@ -4,7 +4,7 @@ const regexMatch = /sh([0-9]{1,10})\|/; // Test that a normal mongo shell gives us some noise in the raw output. { const out = runMongoProgram('mongo', '--port', mongo.port, '--eval', ';'); - const mongoOutput = rawMongoProgramOutput(); + const mongoOutput = rawMongoProgramOutput(".*"); assert.gte(mongoOutput.match(regexMatch).length, 1); } @@ -14,7 +14,7 @@ clearRawMongoProgramOutput(); // Test that a quiet shell does not output anything. { const out = runMongoProgram('mongo', '--port', mongo.port, '--quiet', '--eval', ';'); - const mongoOutput = rawMongoProgramOutput(); + const mongoOutput = rawMongoProgramOutput(".*"); assert.eq(mongoOutput.match(regexMatch), null); } diff --git a/jstests/noPassthrough/shell/shell_history.js b/jstests/noPassthrough/shell/shell_history.js index 14ee3527f22..9b8eb66cec6 100644 --- a/jstests/noPassthrough/shell/shell_history.js +++ b/jstests/noPassthrough/shell/shell_history.js @@ -94,7 +94,7 @@ if (!_isWindows()) { var rc = runProgram("ls", "-l", file.name); assert.eq(rc, 0); - var output = rawMongoProgramOutput(); + var output = rawMongoProgramOutput(".*"); var fields = output.split(" "); // First field is the prefix, second field is the `ls -l` permissions. assert.eq(fields[1].substr(0, 10), "-rw-------", targetFile + " has bad permissions"); diff --git a/jstests/noPassthrough/shell/shell_interactive.js b/jstests/noPassthrough/shell/shell_interactive.js index 0d0b0559fa2..d3c14c91aa1 100644 --- a/jstests/noPassthrough/shell/shell_interactive.js +++ b/jstests/noPassthrough/shell/shell_interactive.js @@ -5,7 +5,7 @@ if (!_isWindows()) { clearRawMongoProgramOutput(); var rc = runProgram("mongo", "--nodb", "--quiet", "--eval", "print(isInteractive())"); assert.eq(rc, 0); - var output = rawMongoProgramOutput(); + var output = rawMongoProgramOutput(".*"); var response = (output.split('\n').slice(-2)[0]).split(' ')[1]; assert.eq(response, "false", "Expected 'false' in script mode"); // now try interactive @@ -13,7 +13,7 @@ if (!_isWindows()) { rc = runProgram( "mongo", "--nodb", "--quiet", "--shell", "--eval", "print(isInteractive()); quit()"); assert.eq(rc, 0); - output = rawMongoProgramOutput(); + output = rawMongoProgramOutput(".*"); response = (output.split('\n').slice(-2)[0]).split(' ')[1]; assert.eq(response, "true", "Expected 'true' in interactive mode"); } \ No newline at end of file diff --git a/jstests/noPassthrough/validate/validate_hook_resume_fcv_upgrade.js b/jstests/noPassthrough/validate/validate_hook_resume_fcv_upgrade.js index 5f7e7fd8aa1..b41f0051e36 100644 --- a/jstests/noPassthrough/validate/validate_hook_resume_fcv_upgrade.js +++ b/jstests/noPassthrough/validate/validate_hook_resume_fcv_upgrade.js @@ -53,7 +53,7 @@ function runValidateHook(testCase) { // will return all of their output. testCase.teardown(); - return rawMongoProgramOutput(); + return rawMongoProgramOutput(".*"); } function testStandalone(additionalSetupFn, { diff --git a/jstests/noPassthrough/version.js b/jstests/noPassthrough/version.js index 83d528b9957..1cf57f8640f 100644 --- a/jstests/noPassthrough/version.js +++ b/jstests/noPassthrough/version.js @@ -16,7 +16,7 @@ const testVersionOutput = (exePath) => { runNonMongoProgram(exePath, "--version"); - const out = rawMongoProgramOutput().split('\n'); + const out = rawMongoProgramOutput(".*").split('\n'); assert.neq(out[0].match(dbVersionMatch), null); assert.neq(out[1].match(buildInfoMatch), null); diff --git a/jstests/noPassthrough/wt_integration/wt_operation_stats.js b/jstests/noPassthrough/wt_integration/wt_operation_stats.js index 3e8bcae041a..c1a88028f6e 100644 --- a/jstests/noPassthrough/wt_integration/wt_operation_stats.js +++ b/jstests/noPassthrough/wt_integration/wt_operation_stats.js @@ -12,7 +12,7 @@ const readStatRegx = /"storage":{"data":{"bytesRead":([0-9]+)/; let checkLogStats = function() { // Check if the log output contains the expected statistics. - let mongodLogs = rawMongoProgramOutput(); + let mongodLogs = rawMongoProgramOutput(".*"); let lines = mongodLogs.split('\n'); let match; let logLineCount = 0; diff --git a/jstests/ocsp/lib/mock_ocsp.js b/jstests/ocsp/lib/mock_ocsp.js index f96a8cf9059..64a1eb160d6 100644 --- a/jstests/ocsp/lib/mock_ocsp.js +++ b/jstests/ocsp/lib/mock_ocsp.js @@ -115,7 +115,7 @@ export class MockOCSPServer { assert.soon(function() { // Change this line if the OCSP endpoint changes - return rawMongoProgramOutput().search("Launching debugserver on port 8100") !== -1; + return rawMongoProgramOutput(".*").search("Launching debugserver on port 8100") !== -1; }); sleep(2000); diff --git a/jstests/ocsp/lib/ocsp_helpers.js b/jstests/ocsp/lib/ocsp_helpers.js index 447b9a7b620..2d6f0d2ee20 100644 --- a/jstests/ocsp/lib/ocsp_helpers.js +++ b/jstests/ocsp/lib/ocsp_helpers.js @@ -90,7 +90,7 @@ export const OCSP_REVOKED = "OCSPCertificateStatusRevoked"; export var assertClientConnectFails = function(conn, reason) { clearRawMongoProgramOutput(); assert.neq(clientConnect(conn), 0); - const errmsg = rawMongoProgramOutput(); + const errmsg = rawMongoProgramOutput(".*"); if (typeof reason === 'string' || reason instanceof RegExp) { assert.neq(errmsg.search(reason), -1); } diff --git a/jstests/ocsp/ocsp_basic.js b/jstests/ocsp/ocsp_basic.js index 61f654459db..84664657b26 100644 --- a/jstests/ocsp/ocsp_basic.js +++ b/jstests/ocsp/ocsp_basic.js @@ -61,7 +61,7 @@ MongoRunner.stopMongod(conn); // a certificate is revoked. if (determineSSLProvider() === "apple") { const APPLE_OCSP_ERROR_CODE = "CSSMERR_TP_CERT_REVOKED"; - let output = rawMongoProgramOutput(); + let output = rawMongoProgramOutput(".*"); assert(output.search(APPLE_OCSP_ERROR_CODE)); quit(); } diff --git a/jstests/ocsp/ocsp_client_verification_logging.js b/jstests/ocsp/ocsp_client_verification_logging.js index 145637cfe3b..b30eca6b330 100644 --- a/jstests/ocsp/ocsp_client_verification_logging.js +++ b/jstests/ocsp/ocsp_client_verification_logging.js @@ -59,7 +59,7 @@ let runTest = (options) => { 1); runParallelShellSuccess(); - const successOutput = rawMongoProgramOutput(); + const successOutput = rawMongoProgramOutput(".*"); let failOutput; if (ocspFaultType != "") { @@ -88,7 +88,7 @@ let runTest = (options) => { "--verbose", 1)); - failOutput = rawMongoProgramOutput(); + failOutput = rawMongoProgramOutput(".*"); } if (ocspFaultType == FAULT_REVOKED) { diff --git a/jstests/replsets/dbcheck_extra_index_keys_coll_or_index_not_found.js b/jstests/replsets/dbcheck_extra_index_keys_coll_or_index_not_found.js index e1c1fccc0e8..81cf94e81da 100644 --- a/jstests/replsets/dbcheck_extra_index_keys_coll_or_index_not_found.js +++ b/jstests/replsets/dbcheck_extra_index_keys_coll_or_index_not_found.js @@ -364,7 +364,7 @@ function allIndexKeysNotFoundDuringReverseLookup(nDocs, docSuffix, collOpts) { checkHealthLog(secondaryHealthLog, logQueries.allErrorsOrWarningsQuery, 0); if (debugBuild) { - assert(rawMongoProgramOutput().match(/7844803.*could not find any keys in index/), + assert(rawMongoProgramOutput("could not find any keys in index").match(/7844803/), "expected 'could not find any keys in index' log"); } } diff --git a/jstests/replsets/dbcheck_extra_keys_rate_limits.js b/jstests/replsets/dbcheck_extra_keys_rate_limits.js index 8b43988861e..0e385d3f297 100644 --- a/jstests/replsets/dbcheck_extra_keys_rate_limits.js +++ b/jstests/replsets/dbcheck_extra_keys_rate_limits.js @@ -90,8 +90,8 @@ function checkNumBatchesAndSnapshots( ((expectedNumBatches - 1) * snapshotsPerBatch) + lastBatchSnapshots; } const actualNumSnapshots = - rawMongoProgramOutput() - .split(/7844808.*Catalog snapshot for reverse lookup check ending/) + rawMongoProgramOutput("Catalog snapshot for reverse lookup check ending") + .split(/7844808/) .length - 1; assert.eq(actualNumSnapshots, diff --git a/jstests/replsets/get_replication_info_helper.js b/jstests/replsets/get_replication_info_helper.js index 1b9ae0caa3f..00245423048 100644 --- a/jstests/replsets/get_replication_info_helper.js +++ b/jstests/replsets/get_replication_info_helper.js @@ -28,15 +28,16 @@ failPointBeforeFinish.wait(); const callPrintSecondaryReplInfo = startParallelShell( "db.getSiblingDB('admin').printSecondaryReplicationInfo();", syncTarget.port); callPrintSecondaryReplInfo(); -assert(rawMongoProgramOutput().match("InitialSyncSyncSource: " + primary.name)); -assert(rawMongoProgramOutput().match("InitialSyncRemainingEstimatedDuration: ")); +assert(rawMongoProgramOutput("InitialSyncSyncSource: ").match(primary.name)); +let subStr = "InitialSyncRemainingEstimatedDuration: "; +assert(rawMongoProgramOutput(subStr).match(subStr)); clearRawMongoProgramOutput(); const callPrintSlaveReplInfo = startParallelShell("db.getSiblingDB('admin').printSlaveReplicationInfo();", syncTarget.port); callPrintSlaveReplInfo(); -assert(rawMongoProgramOutput().match("InitialSyncSyncSource: " + primary.name)); -assert(rawMongoProgramOutput().match("InitialSyncRemainingEstimatedDuration: ")); +assert(rawMongoProgramOutput("InitialSyncSyncSource: ").match(primary.name)); +assert(rawMongoProgramOutput(subStr).match(subStr)); clearRawMongoProgramOutput(); failPointBeforeFinish.off(); replSet.awaitSecondaryNodes(); @@ -63,7 +64,8 @@ assert(replInfo.now, replInfoString); var mongo = startParallelShell("db.getSiblingDB('admin').printSlaveReplicationInfo();", primary.port); mongo(); -assert(rawMongoProgramOutput().match("behind the primary")); +subStr = "behind the primary"; +assert(rawMongoProgramOutput(subStr).match(subStr)); // get to a primaryless state for (i in replSet.getSecondaries()) { @@ -76,15 +78,16 @@ assert.commandWorked(primary.getDB('admin').runCommand({replSetStepDown: 120, fo // it still works for backwards compatibility. mongo = startParallelShell("db.getSiblingDB('admin').printSlaveReplicationInfo();", primary.port); mongo(); -assert(rawMongoProgramOutput().match("behind the freshest")); +subStr = "behind the freshest"; +assert(rawMongoProgramOutput(subStr).match(subStr)); clearRawMongoProgramOutput(); -assert.eq(rawMongoProgramOutput().match("behind the freshest"), null); +assert.eq(rawMongoProgramOutput(subStr).match(subStr), null); // Ensure that the new helper, printSecondaryReplicationInfo works the same. mongo = startParallelShell("db.getSiblingDB('admin').printSecondaryReplicationInfo();", primary.port); mongo(); -assert(rawMongoProgramOutput().match("behind the freshest")); +assert(rawMongoProgramOutput(subStr).match(subStr)); replSet.stopSet(); \ No newline at end of file diff --git a/jstests/replsets/initiate_or_reconfig_with_non_default_get_last_error_defaults_fails.js b/jstests/replsets/initiate_or_reconfig_with_non_default_get_last_error_defaults_fails.js index 674043226fc..f01972b5aff 100644 --- a/jstests/replsets/initiate_or_reconfig_with_non_default_get_last_error_defaults_fails.js +++ b/jstests/replsets/initiate_or_reconfig_with_non_default_get_last_error_defaults_fails.js @@ -28,7 +28,7 @@ function testInitiate(gleDefaults) { assert.soon( function() { - return rawMongoProgramOutput().search(/Fatal assertion.*5624101/) >= 0; + return rawMongoProgramOutput("Fatal assertion").search(/5624101/) >= 0; }, "Node should have fasserted when initiating with a non-default getLastErrorDefaults field", ReplSetTest.kDefaultTimeoutMS); diff --git a/jstests/replsets/libs/dbcheck_utils.js b/jstests/replsets/libs/dbcheck_utils.js index 81dc33a7bfd..c6a8f39a638 100644 --- a/jstests/replsets/libs/dbcheck_utils.js +++ b/jstests/replsets/libs/dbcheck_utils.js @@ -562,8 +562,8 @@ export function checkSecondaryIndexChecksInDbCheckFeatureFlagEnabled(conn) { export function checkNumSnapshots(debugBuild, expectedNumSnapshots) { if (debugBuild) { const actualNumSnapshots = - rawMongoProgramOutput() - .split(/7844808.*Catalog snapshot for reverse lookup check ending/) + rawMongoProgramOutput("Catalog snapshot for reverse lookup check ending") + .split(/7844808/) .length - 1; assert.eq(actualNumSnapshots, diff --git a/jstests/replsets/libs/rollback_resumable_index_build.js b/jstests/replsets/libs/rollback_resumable_index_build.js index 44d573f8f0f..08ff2a63a56 100644 --- a/jstests/replsets/libs/rollback_resumable_index_build.js +++ b/jstests/replsets/libs/rollback_resumable_index_build.js @@ -216,7 +216,7 @@ export class RollbackResumableIndexBuildTest { // Wait until the parallel shells have all started. assert.soon(() => { - return (rawMongoProgramOutput().match(/"id":5113600/g) || []).length === + return (rawMongoProgramOutput("\"id\":5113600").match(/"id":5113600/g) || []).length === buildUUIDs.length; }); getLogFp.off(); diff --git a/jstests/replsets/libs/secondary_reads_test.js b/jstests/replsets/libs/secondary_reads_test.js index 7ac266486c8..de94ad9537b 100644 --- a/jstests/replsets/libs/secondary_reads_test.js +++ b/jstests/replsets/libs/secondary_reads_test.js @@ -74,7 +74,7 @@ export function SecondaryReadsTest(name = "secondary_reads_test") { return function() { assert.soon(function() { - return rawMongoProgramOutput().match(failPoint + " fail point enabled"); + return rawMongoProgramOutput("fail point enabled").match(failPoint); }); }; }; diff --git a/jstests/replsets/print_secondary_replication_info_unreachable_secondary.js b/jstests/replsets/print_secondary_replication_info_unreachable_secondary.js index c6d46ab20dc..f2379fe17a8 100644 --- a/jstests/replsets/print_secondary_replication_info_unreachable_secondary.js +++ b/jstests/replsets/print_secondary_replication_info_unreachable_secondary.js @@ -18,7 +18,7 @@ replSet.waitForState(secondary, ReplSetTest.State.DOWN); const joinShell = startParallelShell("db.getSiblingDB('admin').printSecondaryReplicationInfo();", primary.port); joinShell(); -assert( - rawMongoProgramOutput().match("no replication info, yet. State: \\(not reachable/healthy\\)")); +assert(rawMongoProgramOutput("no replication info, yet. State: ") + .match("\\(not reachable/healthy\\)")); replSet.stopSet(); \ No newline at end of file diff --git a/jstests/replsets/repl_startup_error_no_hang_on_shutdown.js b/jstests/replsets/repl_startup_error_no_hang_on_shutdown.js index e7ec1290d10..648c7f16aea 100644 --- a/jstests/replsets/repl_startup_error_no_hang_on_shutdown.js +++ b/jstests/replsets/repl_startup_error_no_hang_on_shutdown.js @@ -35,7 +35,7 @@ assert.eq(exitCode, MongoRunner.EXIT_ABRUPT); assert.soon( function() { - return rawMongoProgramOutput().search(/Fatal assertion.*6111701/) >= 0; + return rawMongoProgramOutput("Fatal assertion").search(/6111701/) >= 0; }, "Node should have fasserted upon encountering a fatal error during startup", ReplSetTest.kDefaultTimeoutMS); \ No newline at end of file diff --git a/jstests/replsets/rollback_time_limit_param.js b/jstests/replsets/rollback_time_limit_param.js index a3b43a25e0e..50426c43e0d 100644 --- a/jstests/replsets/rollback_time_limit_param.js +++ b/jstests/replsets/rollback_time_limit_param.js @@ -17,7 +17,7 @@ assert.throws(function() { rstWithBadStartupOptions.startSet(); }); -assert(rawMongoProgramOutput().match("Bad value for parameter \"rollbackTimeLimitSecs\""), +assert(rawMongoProgramOutput("Bad value for parameter").match("\"rollbackTimeLimitSecs\""), "failed to reject bad value for parameter"); // Now initialize the same parameter correctly on startup. diff --git a/jstests/replsets/rollback_unclean_shutdowns_parameter_obeyed.js b/jstests/replsets/rollback_unclean_shutdowns_parameter_obeyed.js index cb2cb3ffc6b..f464a8f09c6 100644 --- a/jstests/replsets/rollback_unclean_shutdowns_parameter_obeyed.js +++ b/jstests/replsets/rollback_unclean_shutdowns_parameter_obeyed.js @@ -30,6 +30,7 @@ rollbackTest.transitionToSyncSourceOperationsDuringRollback(); rollbackTest.transitionToSteadyStateOperations(); // Make sure no unclean shutdowns occurred. -assert.eq(rawMongoProgramOutput().search(/Detected unclean shutdown/), -1); +const subStr = "Detected unclean shutdown"; +assert.eq(rawMongoProgramOutput(subStr).search(subStr), -1); rollbackTest.stop(); \ No newline at end of file diff --git a/jstests/replsets/startup_recovery_for_restore_needs_rollback.js b/jstests/replsets/startup_recovery_for_restore_needs_rollback.js index 9ab7d0b24b1..4cdcc46f22f 100644 --- a/jstests/replsets/startup_recovery_for_restore_needs_rollback.js +++ b/jstests/replsets/startup_recovery_for_restore_needs_rollback.js @@ -150,7 +150,8 @@ assert.commandWorked(restoreNode.adminCommand( {'configureFailPoint': 'hangBeforeUnrecoverableRollbackError', 'mode': 'off'})); // This node should not come back up, because it has no stable timestamp to recover to. -assert.soon(() => (rawMongoProgramOutput().search("UnrecoverableRollbackError") >= 0)); +const subStr = "UnrecoverableRollbackError"; +assert.soon(() => (rawMongoProgramOutput(subStr).search(subStr) >= 0)); // Hide the exit code from stopSet. waitMongoProgram(parseInt(restoreNode.port)); diff --git a/jstests/replsets/startup_recovery_for_restore_restarts.js b/jstests/replsets/startup_recovery_for_restore_restarts.js index 48ed39bfc51..cf6d5fc182c 100644 --- a/jstests/replsets/startup_recovery_for_restore_restarts.js +++ b/jstests/replsets/startup_recovery_for_restore_restarts.js @@ -128,23 +128,25 @@ rst.start(restoreNode, }) }, true /* restart */); +let subStr = "hangAfterCollectionInserts fail point enabled"; assert.soon(() => { // Can't use checklog because we can't connect to the mongo in startup mode. - return rawMongoProgramOutput().search("hangAfterCollectionInserts fail point enabled") !== -1; + return rawMongoProgramOutput(subStr).search(subStr) !== -1; }); // We need to make sure we get a checkpoint after the failpoint is hit, so we clear the output after // hitting it. Occasionally we'll miss a checkpoint as a result of clearing the output, but we'll // get another one a second later. clearRawMongoProgramOutput(); // Ensure the checkpoint starts after the insert. +subStr = "WT_VERB_CHECKPOINT.*saving checkpoint snapshot min"; assert.soon(() => { - return rawMongoProgramOutput().search("WT_VERB_CHECKPOINT.*saving checkpoint snapshot min") !== - -1; + return rawMongoProgramOutput(subStr).search(subStr) !== -1; }); // Ensure that we wait for a checkpoint completed log message that comes strictly after the above // checkpoint started message. clearRawMongoProgramOutput(); +subStr = "Completed unstable checkpoint."; assert.soon(() => { - return rawMongoProgramOutput().search("Completed unstable checkpoint.") !== -1; + return rawMongoProgramOutput(subStr).search(subStr) !== -1; }); jsTestLog("Restarting restore node uncleanly"); diff --git a/jstests/resmoke_selftest/shell_hang_analyzer.js b/jstests/resmoke_selftest/shell_hang_analyzer.js index b0c68d8467a..0552402311b 100644 --- a/jstests/resmoke_selftest/shell_hang_analyzer.js +++ b/jstests/resmoke_selftest/shell_hang_analyzer.js @@ -28,7 +28,7 @@ if (TestData && TestData.inEvergreen) { return !checkProgram(child.pid).alive; }, undefined, undefined, undefined, {runHangAnalyzer: false}); - const lines = rawMongoProgramOutput().split('\n'); + const lines = rawMongoProgramOutput(".*").split('\n'); const buildInfo = globalThis.db.getServerBuildInfo(); if (buildInfo.isAddressSanitizerActive() || buildInfo.isThreadSanitizerActive()) { assert.soon(() => { @@ -70,7 +70,7 @@ clearRawMongoProgramOutput(); MongoRunner.runHangAnalyzer.disable(); assert.eq(undefined, MongoRunner.runHangAnalyzer([20200125])); -const lines = rawMongoProgramOutput().split('\n'); +const lines = rawMongoProgramOutput(".*").split('\n'); // Nothing should be executed, so there's no output. assert.eq(lines, ['']); })(); @@ -91,7 +91,7 @@ try { TestData.inEvergreen = origInEvg; } -const lines = rawMongoProgramOutput().split('\n'); +const lines = rawMongoProgramOutput(".*").split('\n'); // Nothing should be executed, so there's no output. assert.eq(lines, ['']); })(); diff --git a/jstests/sharding/libs/proxy_protocol.js b/jstests/sharding/libs/proxy_protocol.js index 094192b9a91..ef89c1e157e 100644 --- a/jstests/sharding/libs/proxy_protocol.js +++ b/jstests/sharding/libs/proxy_protocol.js @@ -79,7 +79,7 @@ export class ProxyProtocolServer { // Wait for the web server to start assert.soon(function() { - return rawMongoProgramOutput().search("Starting proxy protocol server...") !== -1; + return rawMongoProgramOutput(".*").search("Starting proxy protocol server...") !== -1; }); print("Proxy Protocol Server sucessfully started."); diff --git a/jstests/sharding/libs/sharded_transactions_helpers.js b/jstests/sharding/libs/sharded_transactions_helpers.js index 9eee2943c9f..776da7b05f8 100644 --- a/jstests/sharding/libs/sharded_transactions_helpers.js +++ b/jstests/sharding/libs/sharded_transactions_helpers.js @@ -100,7 +100,7 @@ export function waitForFailpoint(hitFailpointStr, numTimes, timeout) { assert.soon( function() { const re = new RegExp(hitFailpointStr, 'g' /* find all occurrences */); - return (rawMongoProgramOutput().match(re) || []).length == numTimes; + return (rawMongoProgramOutput(hitFailpointStr).match(re) || []).length == numTimes; }, 'Failed to find "' + hitFailpointStr + '" logged ' + numTimes + ' times', timeout, diff --git a/jstests/sharding/set_fcv_logging.js b/jstests/sharding/set_fcv_logging.js index b9ddf312ff3..6ab0224253d 100644 --- a/jstests/sharding/set_fcv_logging.js +++ b/jstests/sharding/set_fcv_logging.js @@ -22,47 +22,47 @@ const SetFCVStatus = Object.freeze({called: 1, transitioning: 2, successful: 3}) */ function assertLogs(status, upgradeOrDowngrade, serverType, numShardServers) { if (status >= SetFCVStatus.called) { - assert.soon(() => rawMongoProgramOutput().match(/\"id\":6744300/), + assert.soon(() => rawMongoProgramOutput(".*").match(/\"id\":6744300/), '"FCV ' + upgradeOrDowngrade + ' called" log not found'); } else { - assert(rawMongoProgramOutput().match(/\"id\":6744300/) == null, + assert(rawMongoProgramOutput(".*").match(/\"id\":6744300/) == null, 'should not log but "FCV ' + upgradeOrDowngrade + ' called" log found'); } if (status >= SetFCVStatus.transitioning) { - assert.soon(() => rawMongoProgramOutput().match(/\"id\":6744301/), + assert.soon(() => rawMongoProgramOutput(".*").match(/\"id\":6744301/), '"FCV ' + upgradeOrDowngrade + ' in progress" log not found'); } else { - assert(rawMongoProgramOutput().match(/\"id\":6744301/) == null, + assert(rawMongoProgramOutput(".*").match(/\"id\":6744301/) == null, 'should not log but "FCV ' + upgradeOrDowngrade + ' in progress" log found'); } if (status >= SetFCVStatus.successful) { - assert.soon(() => rawMongoProgramOutput().match(/\"id\":6744302/), + assert.soon(() => rawMongoProgramOutput(".*").match(/\"id\":6744302/), '"FCV ' + upgradeOrDowngrade + ' success" log not found'); } else { - assert(rawMongoProgramOutput().match(/\"id\":6744302/) == null, + assert(rawMongoProgramOutput(".*").match(/\"id\":6744302/) == null, 'should not log but "FCV ' + upgradeOrDowngrade + ' success" log found'); } if (serverType === "replica set/maintenance mode") { assert.soon(() => { - let matchRes = - rawMongoProgramOutput().match(/\"serverType\":"replica set\/maintenance mode"/g); + let matchRes = rawMongoProgramOutput(".*").match( + /\"serverType\":"replica set\/maintenance mode"/g); return matchRes != null && matchRes.length == status; }, "should have " + status + " log(s) with serverType: replica set/maintenance mode"); } else if (serverType === "shardedCluster") { assert.soon(() => { - let matchRes = rawMongoProgramOutput().match(/\"serverType\":"config server"/g); + let matchRes = rawMongoProgramOutput(".*").match(/\"serverType\":"config server"/g); return matchRes != null && matchRes.length == status; }, "should have " + status + " log(s) with serverType: config server"); // If the FCV change failed before the config server reached the transitioning state, // there should not be any logs containing 'shard server'. if (status >= SetFCVStatus.transitioning) { assert.soon(() => { - let matchRes = rawMongoProgramOutput().match(/\"serverType\":"shard server"/g); + let matchRes = rawMongoProgramOutput(".*").match(/\"serverType\":"shard server"/g); return matchRes != null && matchRes.length == numShardServers * status; }, "should have " + numShardServers * status + " log(s) with serverType: shard server"); } else { - assert(rawMongoProgramOutput().match(/\"serverType\":"shard server"/g) == null, + assert(rawMongoProgramOutput(".*").match(/\"serverType\":"shard server"/g) == null, 'should not have log containing shard server'); } } diff --git a/jstests/sharding/shard_identity_rollback.js b/jstests/sharding/shard_identity_rollback.js index b8968f32f66..06f39847906 100644 --- a/jstests/sharding/shard_identity_rollback.js +++ b/jstests/sharding/shard_identity_rollback.js @@ -92,7 +92,7 @@ jsTest.log("Waiting for original primary to rollback and shut down"); // Wait until the node shuts itself down during the rollback. We will hit the first assertion if // we rollback using 'recoverToStableTimestamp'. assert.soon(() => { - return (rawMongoProgramOutput().search(/Fatal assertion.*(40498|50712)/) !== -1); + return (rawMongoProgramOutput(".*").search(/Fatal assertion.*(40498|50712)/) !== -1); }); // Restart the original primary again. This time, the shardIdentity document should already be diff --git a/jstests/sharding/time_zone_info_mongos.js b/jstests/sharding/time_zone_info_mongos.js index 4e2e0afb27f..e9a8d89f6fc 100644 --- a/jstests/sharding/time_zone_info_mongos.js +++ b/jstests/sharding/time_zone_info_mongos.js @@ -34,7 +34,7 @@ function testWithGoodTimeZoneDir(tzGoodInfoDir) { () => 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/)); + assert.neq(-1, rawMongoProgramOutput(".*").search(/Fatal assertion.*40475/)); // Test that a non-existent timezone directory causes mongoS startup to fail. assert.throws( @@ -42,8 +42,8 @@ function testWithGoodTimeZoneDir(tzGoodInfoDir) { [], "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")); + assert(rawMongoProgramOutput(".*").includes("Error creating service context") || + rawMongoProgramOutput(".*").includes("Failed to create service context")); // Enable sharding on the test DB and ensure its primary is st.shard0.shardName. assert.commandWorked( diff --git a/jstests/sharding/txn_commit_optimizations_for_read_only_shards.js b/jstests/sharding/txn_commit_optimizations_for_read_only_shards.js index 6907c82453e..0de94b97307 100644 --- a/jstests/sharding/txn_commit_optimizations_for_read_only_shards.js +++ b/jstests/sharding/txn_commit_optimizations_for_read_only_shards.js @@ -26,7 +26,7 @@ import { // logged at an earlier wall clock time. function waitForLog(logLine, times) { assert.soon(function() { - const matches = rawMongoProgramOutput().match(new RegExp(logLine, "g")) || []; + const matches = rawMongoProgramOutput(".*").match(new RegExp(logLine, "g")) || []; return matches.length === times; }, 'Failed to find "' + logLine + '" logged ' + times + ' times'); } diff --git a/jstests/slow1/terminate_during_shutdown_checkpoint.js b/jstests/slow1/terminate_during_shutdown_checkpoint.js index 733cd189adc..d0ad3de2a74 100644 --- a/jstests/slow1/terminate_during_shutdown_checkpoint.js +++ b/jstests/slow1/terminate_during_shutdown_checkpoint.js @@ -167,7 +167,7 @@ while (numUncleanShutdowns < kNumUncleanShutdowns) { }, primary.port); assert.soon(() => { - const logContents = rawMongoProgramOutput(); + const logContents = rawMongoProgramOutput(".*"); return logContents.indexOf("close_ckpt") > 0; }); diff --git a/jstests/ssl/cluster_member.js b/jstests/ssl/cluster_member.js index 764bf734bf9..36a533bef92 100644 --- a/jstests/ssl/cluster_member.js +++ b/jstests/ssl/cluster_member.js @@ -18,13 +18,13 @@ if (determineSSLProvider() !== "openssl") { jsTest.log('No clusterAuthMode set'); clearRawMongoProgramOutput(); assert.throws(() => MongoRunner.runMongod(opts)); - assert(rawMongoProgramOutput().includes(errmsg)); + assert(rawMongoProgramOutput(".*").includes(errmsg)); jsTest.log('clusterAuthMode == keyFile'); clearRawMongoProgramOutput(); opts.clusterAuthMode = 'keyFile'; assert.throws(() => MongoRunner.runMongod(opts)); - assert(rawMongoProgramOutput().includes(errmsg)); + assert(rawMongoProgramOutput(".*").includes(errmsg)); } function authAndDo(port, cert, cmd = ';') { diff --git a/jstests/ssl/macos_encrypted_pem.js b/jstests/ssl/macos_encrypted_pem.js index a8c64664550..a4738729276 100644 --- a/jstests/ssl/macos_encrypted_pem.js +++ b/jstests/ssl/macos_encrypted_pem.js @@ -14,7 +14,7 @@ requireSSLProvider('apple', function() { assert.throws(() => MongoRunner.runMongod(config), [], "MongoD unexpectedly started up"); - assert.eq(rawMongoProgramOutput().includes( + assert.eq(rawMongoProgramOutput(".*").includes( "Using encrypted PKCS#1/PKCS#8 PEM files is not supported on this platform"), true); }); diff --git a/jstests/ssl/repl_ssl_split_horizon.js b/jstests/ssl/repl_ssl_split_horizon.js index c66a950ae93..715756e7bb5 100644 --- a/jstests/ssl/repl_ssl_split_horizon.js +++ b/jstests/ssl/repl_ssl_split_horizon.js @@ -30,7 +30,7 @@ if (rc != 0) { } // Output is of the format: 'glibc x.yz' - var output = rawMongoProgramOutput(); + var output = rawMongoProgramOutput(".*"); clearRawMongoProgramOutput(); jsTestLog(`getconf GNU_LIBC_VERSION\n${output}`); @@ -45,7 +45,7 @@ if (rc != 0) { quit(); } - var osRelease = rawMongoProgramOutput(); + var osRelease = rawMongoProgramOutput(".*"); clearRawMongoProgramOutput(); jsTestLog(`cat /etc/os-release\n${osRelease}`); diff --git a/jstests/ssl/shell_option_parsing.js b/jstests/ssl/shell_option_parsing.js index 1491484dd2c..9824acf1b44 100644 --- a/jstests/ssl/shell_option_parsing.js +++ b/jstests/ssl/shell_option_parsing.js @@ -53,7 +53,7 @@ function testConnect(expectPasswordPrompt, expectSuccess, ...args) { var clientPID = _startMongoProgram({args: command}); assert.soon(function() { - const output = rawMongoProgramOutput(); + const output = rawMongoProgramOutput(".*"); if (expectPasswordPrompt) { if (output.includes("Enter password:")) { stopMongoProgramByPid(clientPID); diff --git a/jstests/ssl/ssl_alert_reporting.js b/jstests/ssl/ssl_alert_reporting.js index a04d893f107..e199b213756 100644 --- a/jstests/ssl/ssl_alert_reporting.js +++ b/jstests/ssl/ssl_alert_reporting.js @@ -53,7 +53,7 @@ function runTest(serverDisabledProtos, clientDisabledProtos) { ...clientOptions, "--tlsDisabledProtocols", clientDisabledProtos); - mongoOutput = rawMongoProgramOutput(); + mongoOutput = rawMongoProgramOutput(".*"); return mongoOutput.match(expectedRegex); }, "Mongo shell output was as follows:\n" + mongoOutput + "\n************", 60 * 1000); diff --git a/jstests/ssl/ssl_ca_options.js b/jstests/ssl/ssl_ca_options.js index 91bbed76511..4aecd045301 100644 --- a/jstests/ssl/ssl_ca_options.js +++ b/jstests/ssl/ssl_ca_options.js @@ -8,7 +8,7 @@ var opts = { assert.throws(() => MongoRunner.runMongod(opts), [], "MongoD started successfully with neither tlsCAFile nor tlsUseSystemCA"); -assert(rawMongoProgramOutput().includes( +assert(rawMongoProgramOutput(".*").includes( "The use of TLS without specifying a chain of trust is no longer supported")); clearRawMongoProgramOutput(); @@ -22,7 +22,7 @@ opts = { assert.throws(() => MongoRunner.runMongod(opts), [], "MongoD started successfully with both tlsCAFile and tlsUseSystemCA"); -assert(rawMongoProgramOutput().includes( +assert(rawMongoProgramOutput(".*").includes( "The use of both a CA File and the System Certificate store is not supported")); clearRawMongoProgramOutput(); @@ -37,7 +37,7 @@ opts = { assert.throws(() => MongoRunner.runMongod(opts), [], "MongoD started successfully with both tlsCAFile and tlsUseSystemCA"); -assert(rawMongoProgramOutput().includes( +assert(rawMongoProgramOutput(".*").includes( "The use of both a CA File and the System Certificate store is not supported")); clearRawMongoProgramOutput(); @@ -50,7 +50,7 @@ opts = { assert.throws(() => MongoRunner.runMongod(opts), [], "MongoD started successfully with tlsClusterCAFile without tlsCAFile"); -assert(rawMongoProgramOutput().includes( +assert(rawMongoProgramOutput(".*").includes( "Specifying a tlsClusterCAFile requires a tlsCAFile also be specified")); clearRawMongoProgramOutput(); @@ -64,5 +64,5 @@ opts = { assert.throws(() => MongoRunner.runMongod(opts), [], "MongoD started successfully with tlsClusterCAFile without tlsCAFile"); -assert(rawMongoProgramOutput().includes( +assert(rawMongoProgramOutput(".*").includes( "Specifying a tlsClusterCAFile requires a tlsCAFile also be specified")); \ No newline at end of file diff --git a/jstests/ssl/ssl_cert_selector_apple.js b/jstests/ssl/ssl_cert_selector_apple.js index e27f47dfb88..f3dfd7339da 100644 --- a/jstests/ssl/ssl_cert_selector_apple.js +++ b/jstests/ssl/ssl_cert_selector_apple.js @@ -24,7 +24,7 @@ requireSSLProvider('apple', function() { // criteria. In this case, we use -c, matching common name, and -Z, which includes SHA-1 and // SHA-256 thumbprints in the output. assert.eq(0, runNonMongoProgram("security", "find-certificate", "-c", subject, "-Z")); - const out = rawMongoProgramOutput(); + const out = rawMongoProgramOutput(".*"); const kSearchStr = "SHA-1 hash: "; const kHashHexitLen = 40; @@ -85,7 +85,7 @@ requireSSLProvider('apple', function() { const mongod = MongoRunner.runMongod(opts); assert.soon(function() { - const log = rawMongoProgramOutput(); + const log = rawMongoProgramOutput(".*"); if ((cert.name === null) || (cluster.name === null)) { // Invalid search criteria should fail. return log.search('Certificate selector returned no results') >= 0; diff --git a/jstests/ssl/ssl_client_bad_certificate_warning.js b/jstests/ssl/ssl_client_bad_certificate_warning.js index de6395ada11..a478e611b05 100644 --- a/jstests/ssl/ssl_client_bad_certificate_warning.js +++ b/jstests/ssl/ssl_client_bad_certificate_warning.js @@ -12,7 +12,7 @@ function testConnect(outputLog, ...args) { const clientPID = _startMongoProgram({args: command}); assert.soon(function() { - const output = rawMongoProgramOutput(); + const output = rawMongoProgramOutput(".*"); if (output.includes(outputLog)) { stopMongoProgramByPid(clientPID); return true; diff --git a/jstests/ssl/ssl_client_certificate_warning_suppression.js b/jstests/ssl/ssl_client_certificate_warning_suppression.js index 7d743263a4c..fc4af18be17 100644 --- a/jstests/ssl/ssl_client_certificate_warning_suppression.js +++ b/jstests/ssl/ssl_client_certificate_warning_suppression.js @@ -37,15 +37,15 @@ function test(suppress) { // logged before it. assert.soon( () => { - const log = rawMongoProgramOutput(); + const log = rawMongoProgramOutput(".*"); return log.search('client metadata') !== -1; }, "logfile should contain 'client metadata'.\n" + - "Log File Contents\n==============================\n" + rawMongoProgramOutput() + + "Log File Contents\n==============================\n" + rawMongoProgramOutput(".*") + "\n==============================\n"); // Now check for the message - const log = rawMongoProgramOutput(); + const log = rawMongoProgramOutput(".*"); assert.eq(suppress, log.match(/[N,n]o SSL certificate provided by peer/) === null); try { diff --git a/jstests/ssl/ssl_cn_with_san.js b/jstests/ssl/ssl_cn_with_san.js index 534295ec4b8..e92980d4ec4 100644 --- a/jstests/ssl/ssl_cn_with_san.js +++ b/jstests/ssl/ssl_cn_with_san.js @@ -25,7 +25,7 @@ const mongo = runMongoProgram('mongo', ';', '--tlsAllowInvalidHostnames'); assert.neq(mongo, 0, "Shell connected when it should have failed"); -assert(rawMongoProgramOutput().includes(' would have matched, but was overridden by SAN'), +assert(rawMongoProgramOutput(".*").includes(' would have matched, but was overridden by SAN'), 'Expected detail warning not seen'); // On OpenSSL only, start without `tlsAllowInvalidHostnames` @@ -35,7 +35,7 @@ if (determineSSLProvider() === 'openssl') { const mongo = runMongoProgram( 'mongo', '--tls', '--tlsCAFile', CA, 'localhost:' + mongod.port, '--eval', ';'); assert.neq(mongo, 0, "Shell connected when it should have failed"); - assert(rawMongoProgramOutput().includes( + assert(rawMongoProgramOutput(".*").includes( 'CN: localhost would have matched, but was overridden by SAN'), 'Expected detail warning not seen'); } diff --git a/jstests/ssl/ssl_invalid_selector.js b/jstests/ssl/ssl_invalid_selector.js index bc19b1f1445..ccb84510e4d 100644 --- a/jstests/ssl/ssl_invalid_selector.js +++ b/jstests/ssl/ssl_invalid_selector.js @@ -40,7 +40,7 @@ function testStartupFails(testCase) { assert.throws(() => { MongoRunner.runMongod(opts); }); - assert(rawMongoProgramOutput().includes(testCase.error)); + assert(rawMongoProgramOutput(".*").includes(testCase.error)); } requireSSLProvider('windows', function() { diff --git a/jstests/ssl/ssl_invalid_server_cert.js b/jstests/ssl/ssl_invalid_server_cert.js index fed9a49fce2..1e8a954951e 100644 --- a/jstests/ssl/ssl_invalid_server_cert.js +++ b/jstests/ssl/ssl_invalid_server_cert.js @@ -14,7 +14,7 @@ function runTest(name, config, expect) { } assert.eq(null, mongod, 'Mongod started unexpectedly'); - const output = rawMongoProgramOutput(); + const output = rawMongoProgramOutput(".*"); assert.eq( true, output.includes(expect), "Server failure message did not include '" + expect + "'"); } diff --git a/jstests/ssl/ssl_mongodb_x509.js b/jstests/ssl/ssl_mongodb_x509.js index 0325ffb51b5..a65f2f0936f 100644 --- a/jstests/ssl/ssl_mongodb_x509.js +++ b/jstests/ssl/ssl_mongodb_x509.js @@ -86,5 +86,6 @@ assert.throws(() => MongoRunner.runMongos({ }), [], "mongos started with x509 clusterAuthMode but no CA file"); -assert.neq(-1, rawMongoProgramOutput().search("No TLS certificate validation can be performed")); +assert.neq(-1, + rawMongoProgramOutput(".*").search("No TLS certificate validation can be performed")); configRS.stopSet(); diff --git a/jstests/ssl/x509_all_the_oids.js b/jstests/ssl/x509_all_the_oids.js index 4afcae5ac99..ca2b31a58c7 100644 --- a/jstests/ssl/x509_all_the_oids.js +++ b/jstests/ssl/x509_all_the_oids.js @@ -21,7 +21,7 @@ function runTest(conn) { // We expect failure, since we can't create a user with this massive username in WT. // But at least make sure the error message is sensible. assert.neq(exitCode, 0); - const output = rawMongoProgramOutput(); + const output = rawMongoProgramOutput(".*"); const NAME = 'role=Datum-72,pseudonym=Datum-65,dmdName=Datum-54,deltaRevocationList=Datum-53,supportedAlgorithms=Datum-52,houseIdentifier=Datum-51,uniqueMember=Datum-50,distinguishedName=Datum-49,protocolInformation=Datum-48,enhancedSearchGuide=Datum-47,dnQualifier=Datum-46,x500UniqueIdentifier=Datum-45,generationQualifier=Datum-44,initials=Datum-43,GN=Datum-42,name=Datum-41,crossCertificatePair=Datum-40,certificateRevocationList=Datum-39,authorityRevocationList=Datum-38,cACertificate=Datum-37,userCertificate=Datum-36,userPassword=Datum-35,seeAlso=Datum-34,roleOccupant=Datum-33,owner=Datum-32,member=Datum-31,supportedApplicationContext=Datum-30,presentationAddress=Datum-29,preferredDeliveryMethod=Datum-28,destinationIndicator=Datum-27,registeredAddress=Datum-26,internationaliSDNNumber=Datum-25,x121Address=Datum-24,facsimileTelephoneNumber=Datum-23,teletexTerminalIdentifier=Datum-22,telexNumber=Datum-21,telephoneNumber=Datum-20,physicalDeliveryOfficeName=Datum-19,postOfficeBox=Datum-18,postalCode=Datum-17,postalAddress=Datum-16,businessCategory=Datum-15,searchGuide=Datum-14,description=Datum-13,title=Datum-12,OU=Datum-11,O=Datum-10,street=Datum-9,ST=NY,L=Datum-7,C=US,serialNumber=Datum-5,SN=Datum-4,CN=Datum-3'; diff --git a/jstests/ssl/x509_startup_warning.js b/jstests/ssl/x509_startup_warning.js index 41327df3b20..d2216269b38 100644 --- a/jstests/ssl/x509_startup_warning.js +++ b/jstests/ssl/x509_startup_warning.js @@ -22,7 +22,7 @@ function runTest(checkMongos, opts, expectWarningCertifcates, expectWarningHostn } assert.soon(function() { - const output = rawMongoProgramOutput(); + const output = rawMongoProgramOutput(".*"); return ( expectWarningCertifcates == output.includes( diff --git a/jstests/sslSpecial/cluster_auth_x509_subject_attributes.js b/jstests/sslSpecial/cluster_auth_x509_subject_attributes.js index 95cd1d9e3a6..16c2756c0a5 100644 --- a/jstests/sslSpecial/cluster_auth_x509_subject_attributes.js +++ b/jstests/sslSpecial/cluster_auth_x509_subject_attributes.js @@ -49,7 +49,7 @@ const serverCAFile = 'jstests/libs/ca.pem'; function assertNoStart(opts, errmsg) { clearRawMongoProgramOutput(); assert.throws(() => MongoRunner.runMongod(opts)); - assert(rawMongoProgramOutput().includes(errmsg)); + assert(rawMongoProgramOutput(".*").includes(errmsg)); } function checkInvalidConfigurations() { diff --git a/jstests/sslSpecial/tls1_0.js b/jstests/sslSpecial/tls1_0.js index f966729b701..458121bb200 100644 --- a/jstests/sslSpecial/tls1_0.js +++ b/jstests/sslSpecial/tls1_0.js @@ -77,7 +77,7 @@ function test(serverDP, clientDP, shouldSucceed) { didSucceed, shouldSucceed, "Running with " + tojson(serverDP) + "/" + tojson(clientDP)); assert.eq(expectLogMessage, - rawMongoProgramOutput().search('Automatically disabling TLS 1.0') >= 0, + rawMongoProgramOutput(".*").search('Automatically disabling TLS 1.0') >= 0, "TLS 1.0 was/wasn't automatically disabled"); } diff --git a/jstests/ssl_linear/ssl_cert_selector.js b/jstests/ssl_linear/ssl_cert_selector.js index 5e1b7d68377..56bc98a23a4 100644 --- a/jstests/ssl_linear/ssl_cert_selector.js +++ b/jstests/ssl_linear/ssl_cert_selector.js @@ -87,12 +87,12 @@ function testServerSelectorKeyUsage(testCase) { assert.soon( () => { - const log = rawMongoProgramOutput(); + const log = rawMongoProgramOutput(".*"); return log.search(testCase.expectIngressKeyUsed) !== -1; }, `logfile did not contain expected peer certificate info: ${ testCase.expectIngressKeyUsed}.\n` + - "Log File Contents\n==============================\n" + rawMongoProgramOutput() + + "Log File Contents\n==============================\n" + rawMongoProgramOutput(".*") + "\n==============================\n"); jsTestLog("Testing server uses correct key on egress"); diff --git a/jstests/ssl_linear/ssl_with_system_ca.js b/jstests/ssl_linear/ssl_with_system_ca.js index 3c4890c83c1..1084ea41afa 100644 --- a/jstests/ssl_linear/ssl_with_system_ca.js +++ b/jstests/ssl_linear/ssl_with_system_ca.js @@ -35,7 +35,7 @@ if (HOST_TYPE == "linux") { clearRawMongoProgramOutput(); assert.eq( 0, runProgram("openssl", "x509", "-hash", "-noout", "-in", "jstests/libs/trusted-ca.pem")); - let hash = rawMongoProgramOutput(); + let hash = rawMongoProgramOutput(".*"); jsTestLog(hash); // has form: "|sh \n" hash = hash.trim().split(" ")[1]; copyCertificateFile("jstests/libs/trusted-ca.pem", `${certDir}/${hash}.0`); diff --git a/src/mongo/shell/shell_utils_launcher.cpp b/src/mongo/shell/shell_utils_launcher.cpp index ae5175a2a6d..b5890135f16 100644 --- a/src/mongo/shell/shell_utils_launcher.cpp +++ b/src/mongo/shell/shell_utils_launcher.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -144,19 +145,49 @@ void retryWithBackOff(std::function func) { } #endif +// Filters lines that match the regex pattern +std::string filterLinesWithRegex(const std::string& input, const std::regex& pattern) { + std::stringstream ss(input); + std::string line; + std::ostringstream result; + while (std::getline(ss, line)) { + if (std::regex_search(line, pattern)) { + result << line << std::endl; + } + } + + return result.str(); +} + } // namespace -// Output up to BSONObjMaxUserSize characters of the most recent log output in order to -// avoid hitting the 16MB size limit of a BSONObject. +// Output up to BSONObjMaxUserSize characters of the most recent log output. +// +// Users must send a regex as the only argument, which will be passed as a string. +// It is mandatory to provide this argument. +// +// The function will only return logs that match the specified regex. +// If the resulting logs exceed BSONObjMaxUserSize, the function will raise an exception. +// Ensure the provided regex is well-picked to filter only the desired logs and avoid exceeding the +// size limit. BSONObj RawMongoProgramOutput(const BSONObj& args, void* data) { auto programOutputLogger = ProgramRegistry::get(getGlobalServiceContext())->getProgramOutputMultiplexer(); std::string programLog = programOutputLogger->str(); + uassert(ErrorCodes::BadValue, + "A regex pattern must be provided as the only argument. Please ensure you pass a valid " + "regex string to filter the logs.", + !singleArg(args).isNaN()); + std::string regex = singleArg(args).String(); + std::regex pattern(regex); + programLog = filterLinesWithRegex(programLog, pattern); std::size_t sz = programLog.size(); - const string& outputStr = - sz > BSONObjMaxUserSize ? programLog.substr(sz - BSONObjMaxUserSize) : programLog; + uassert(ErrorCodes::BadValue, + "The filtered logs exceed the BSONObjMaxUserSize limit of 16MB. Please use a more " + "constrained regex pattern to reduce the size of the returned logs.", + sz <= BSONObjMaxUserSize); - return BSON("" << outputStr); + return BSON("" << programLog); } BSONObj ClearRawMongoProgramOutput(const BSONObj& args, void* data) {