summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/client_metadata_slowlog_rs.js
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2020-03-13 12:37:28 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-24 16:24:42 +0000
commit04c0ff72fcf81f833188fb3a1d871b2add3a1958 (patch)
tree6b00548c39ef620c75eee50c60a21031a1beb117 /jstests/noPassthrough/client_metadata_slowlog_rs.js
parent6ce438cd66c81c6c5aa9b81fc618ecb8e0964cd7 (diff)
downloadmongo-04c0ff72fcf81f833188fb3a1d871b2add3a1958.tar.gz
SERVER-45299 Make client_metadata_slowlog_rs.js more robust
Diffstat (limited to 'jstests/noPassthrough/client_metadata_slowlog_rs.js')
-rw-r--r--jstests/noPassthrough/client_metadata_slowlog_rs.js40
1 files changed, 8 insertions, 32 deletions
diff --git a/jstests/noPassthrough/client_metadata_slowlog_rs.js b/jstests/noPassthrough/client_metadata_slowlog_rs.js
index 0d2c83a1456..0e297d612fb 100644
--- a/jstests/noPassthrough/client_metadata_slowlog_rs.js
+++ b/jstests/noPassthrough/client_metadata_slowlog_rs.js
@@ -8,36 +8,7 @@ load("jstests/libs/logv2_helpers.js");
(function() {
'use strict';
-let checkLog = function(conn) {
- print(`Checking ${conn.fullOptions.logFile} for client metadata message`);
- let log = cat(conn.fullOptions.logFile);
-
- let predicate = null;
- if (isJsonLog(conn)) {
- predicate =
- /Slow query.*test.foo.*"appName":"MongoDB Shell".*"command":{"find":"foo","filter":{"\$where":{"\$code":"function\(\)/;
- } else {
- predicate =
- /COMMAND .* command test.foo appName: "MongoDB Shell" command: find { find: "foo", filter: { \$where: function\(\)/;
- }
-
- // Dump the log line by line to avoid log truncation
- for (var a of log.split("\n")) {
- print("LOG_FILE_ENTRY: " + a);
- }
-
- assert(predicate.test(log),
- "'Slow query' log line missing in mongod log file!\n" +
- "Log file contents: " + conn.fullOptions.logFile +
- "\n************************************************************\n" + log +
- "\n************************************************************");
-};
-
-let options = {
- useLogFiles: true,
-};
-
-const rst = new ReplSetTest({nodes: 2, nodeOptions: options});
+const rst = new ReplSetTest({nodes: 2});
rst.startSet();
rst.initiate();
@@ -49,6 +20,9 @@ var conn = new Mongo(rst.getURL());
let coll = conn.getCollection("test.foo");
assert.commandWorked(coll.insert({_id: 1}));
+const predicate =
+ /Slow query.*test.foo.*"appName":"MongoDB Shell".*"command":{"find":"foo","filter":{"\$where":{"\$code":"function\(\)/;
+
// Do a really slow query beyond the 100ms threshold
let count = coll.find({
$where: function() {
@@ -58,7 +32,8 @@ let count = coll.find({
})
.readPref('primary')
.toArray();
-checkLog(rst.getPrimary());
+assert.eq(count.length, 1, "expected 1 document");
+assert(checkLog.checkContainsOnce(rst.getPrimary(), predicate));
// Do a really slow query beyond the 100ms threshold
count = coll.find({
@@ -69,7 +44,8 @@ count = coll.find({
})
.readPref('secondary')
.toArray();
-checkLog(rst.getSecondary());
+assert.eq(count.length, 1, "expected 1 document");
+assert(checkLog.checkContainsOnce(rst.getSecondary(), predicate));
rst.stopSet();
})();