diff options
Diffstat (limited to 'src/mongo/shell/check_log.js')
| -rw-r--r-- | src/mongo/shell/check_log.js | 105 |
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 }; })(); })(); |
