blob: b1cb6098584e9842c377c4b8c067148ed697dc26 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/**
* Test that verifies client metadata is logged as part of slow query logging in MongoD in a replica
* set.
* @tags: [requires_replication]
*/
load("jstests/libs/logv2_helpers.js");
(function() {
'use strict';
const numNodes = 2;
const rst = new ReplSetTest({nodes: numNodes});
rst.startSet();
rst.initiate();
rst.awaitReplication();
// Build a new connection based on the replica set URL
var conn = new Mongo(rst.getURL());
let coll = conn.getCollection("test.foo");
assert.commandWorked(coll.insert({_id: 1}, {writeConcern: {w: numNodes, wtimeout: 5000}}));
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() {
sleep(1000);
return true;
}
})
.readPref('primary')
.toArray();
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({
$where: function() {
sleep(1000);
return true;
}
})
.readPref('secondary')
.toArray();
assert.eq(count.length, 1, "expected 1 document");
assert(checkLog.checkContainsOnce(rst.getSecondary(), predicate));
rst.stopSet();
})();
|