blob: 0ae9b4bdd562bdbeac60b7c6a6ab261d07c8ffc8 (
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
53
54
55
56
57
58
59
60
|
/**
* Test that verifies client metadata is logged as part of slow query logging in MongoD in a replica
* set.
* @tags: [requires_replication]
*/
(function() {
'use strict';
let checkLog = function(conn) {
print(`Checking ${conn.fullOptions.logFile} for client metadata message`);
let log = cat(conn.fullOptions.logFile);
assert(
/COMMAND .* command test.foo appName: "MongoDB Shell" command: find { find: "foo", filter: { \$where: function\(\)/
.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});
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}));
// Do a really slow query beyond the 100ms threshold
let count = coll.find({
$where: function() {
sleep(1000);
return true;
}
})
.readPref('primary')
.toArray();
checkLog(rst.getPrimary());
// Do a really slow query beyond the 100ms threshold
count = coll.find({
$where: function() {
sleep(1000);
return true;
}
})
.readPref('secondary')
.toArray();
checkLog(rst.getSecondary());
rst.stopSet();
})();
|