summaryrefslogtreecommitdiff
path: root/src/mongo/shell/check_log.js
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/shell/check_log.js
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/shell/check_log.js')
-rw-r--r--src/mongo/shell/check_log.js105
1 files changed, 20 insertions, 85 deletions
diff --git a/src/mongo/shell/check_log.js b/src/mongo/shell/check_log.js
index e31dd863519..fc74d871cc1 100644
--- a/src/mongo/shell/check_log.js
+++ b/src/mongo/shell/check_log.js
@@ -30,32 +30,6 @@ checkLog = (function() {
* is found in the logs. Note: this function does not throw an exception, so the return
* value should not be ignored.
*/
- const getLogMessage = function(conn, msg) {
- const logMessages = getGlobalLog(conn);
- if (logMessages === null) {
- return null;
- }
- if (msg instanceof RegExp) {
- for (let logMsg of logMessages) {
- if (logMsg.search(msg) != -1) {
- return logMsg;
- }
- }
- } else {
- for (let logMsg of logMessages) {
- if (logMsg.includes(msg)) {
- return logMsg;
- }
- }
- }
- return null;
- };
-
- /*
- * Calls the 'getLog' function on the provided connection 'conn' to see if the provided msg
- * is found in the logs. Note: this function does not throw an exception, so the return
- * value should not be ignored.
- */
const checkContainsOnce = function(conn, msg) {
const logMessages = getGlobalLog(conn);
if (logMessages === null) {
@@ -122,9 +96,26 @@ checkLog = (function() {
return actual === expected;
},
context = null) {
- const messages = getFilteredLogMessages(conn, id, attrsDict, severity, isRelaxed, context);
+ const logMessages = getGlobalLog(conn);
+ if (logMessages === null) {
+ return false;
+ }
+
+ let count = 0;
+ for (let logMsg of logMessages) {
+ let obj;
+ try {
+ obj = JSON.parse(logMsg);
+ } catch (ex) {
+ print('checkLog.checkContainsOnce: JsonJSON.parse() failed: ' + tojson(ex) + ': ' +
+ logMsg);
+ throw ex;
+ }
- const count = messages.length;
+ if (_compareLogs(obj, id, severity, context, attrsDict, isRelaxed)) {
+ count++;
+ }
+ }
return comparator(count, expectedCount);
};
@@ -165,36 +156,6 @@ checkLog = (function() {
};
/*
- * See checkContainsWithCountJson comment.
- */
- const getFilteredLogMessages = function(
- conn, id, attrsDict, severity = null, isRelaxed = false, context = null) {
- const logMessages = getGlobalLog(conn);
- if (logMessages === null) {
- return false;
- }
-
- let messages = [];
-
- for (let logMsg of logMessages) {
- let obj;
- try {
- obj = JSON.parse(logMsg);
- } catch (ex) {
- print('checkLog.checkContainsOnce: JsonJSON.parse() failed: ' + tojson(ex) + ': ' +
- logMsg);
- throw ex;
- }
-
- if (_compareLogs(obj, id, severity, context, attrsDict, isRelaxed)) {
- messages.push(obj);
- }
- }
-
- return messages;
- };
-
- /*
* Calls the 'getLog' function at regular intervals on the provided connection 'conn' until
* the provided 'msg' is found in the logs, or it times out. Throws an exception on timeout.
*/
@@ -210,29 +171,6 @@ checkLog = (function() {
{runHangAnalyzer: false});
};
- /*
- * Calls the 'getLog' function at regular intervals on the provided connection 'conn' until
- * the provided 'msg' is found in the logs and returned, or it times out. Throws an exception on
- * timeout.
- */
- let containsLog = function(conn, msg, timeoutMillis = 5 * 60 * 1000, retryIntervalMS = 300) {
- // Don't run the hang analyzer because we don't expect contains() to always succeed.
- let logMsg = null;
- assert.soon(
- function() {
- logMsg = getLogMessage(conn, msg);
- if (logMsg) {
- return true;
- }
- return false;
- },
- 'Could not find log entries containing the following message: ' + msg,
- timeoutMillis,
- retryIntervalMS,
- {runHangAnalyzer: false});
- return logMsg;
- };
-
let containsJson = function(conn, id, attrsDict, timeoutMillis = 5 * 60 * 1000) {
// Don't run the hang analyzer because we don't expect contains() to always succeed.
assert.soon(
@@ -472,21 +410,18 @@ checkLog = (function() {
return {
getGlobalLog: getGlobalLog,
- getLogMessage: getLogMessage,
checkContainsOnce: checkContainsOnce,
checkContainsOnceJson: checkContainsOnceJson,
checkContainsWithCountJson: checkContainsWithCountJson,
checkContainsWithAtLeastCountJson: checkContainsWithAtLeastCountJson,
checkContainsOnceJsonStringMatch: checkContainsOnceJsonStringMatch,
contains: contains,
- containsLog: containsLog,
containsJson: containsJson,
containsRelaxedJson: containsRelaxedJson,
containsWithCount: containsWithCount,
containsWithAtLeastCount: containsWithAtLeastCount,
formatAsLogLine: formatAsLogLine,
- formatAsJsonLogLine: formatAsJsonLogLine,
- getFilteredLogMessages: getFilteredLogMessages,
+ formatAsJsonLogLine: formatAsJsonLogLine
};
})();
})();