Files
mongo/jstests/core/getlog2.js
Max Hirschhorn 0ed1b71a50 SERVER-31456 Set initial{Cluster,Operation}Time in concurrency suite.
Ensures that the FSM worker threads are guaranteed to observe the
effects of the $config.setup() function being called since they'll
specify an afterClusterTime beyond that point.
2017-10-14 21:54:02 -04:00

65 lines
2.0 KiB
JavaScript

// tests getlog as well as slow querying logging
// We turn off gossiping the mongo shell's clusterTime because it causes the slow command log
// messages to get truncated since they'll exceed 512 characters. The truncated log messages will
// fail to match the find and update patterns defined later on in this test.
TestData.skipGossipingClusterTime = true;
glcol = db.getLogTest2;
glcol.drop();
contains = function(arr, func) {
var i = arr.length;
while (i--) {
if (func(arr[i])) {
return true;
}
}
return false;
};
// test doesn't work when talking to mongos
if (db.isMaster().msg != "isdbgrid") {
// run a slow query
glcol.save({"SENTINEL": 1});
glcol.findOne({
"SENTINEL": 1,
"$where": function() {
sleep(1000);
return true;
}
});
// run a slow update
glcol.update({
"SENTINEL": 1,
"$where": function() {
sleep(1000);
return true;
}
},
{"x": "x"});
var resp = db.adminCommand({getLog: "global"});
assert(resp.ok == 1, "error executing getLog command");
assert(resp.log, "no log field");
assert(resp.log.length > 0, "no log lines");
// ensure that slow query is logged in detail
assert(contains(resp.log, function(v) {
print(v);
var opString = db.getMongo().useReadCommands() ? " find " : " query ";
var filterString = db.getMongo().useReadCommands() ? "filter:" : "command:";
return v.indexOf(opString) != -1 && v.indexOf(filterString) != -1 &&
v.indexOf("keysExamined:") != -1 && v.indexOf("docsExamined:") != -1 &&
v.indexOf("SENTINEL") != -1;
}));
// same, but for update
assert(contains(resp.log, function(v) {
return v.indexOf(" update ") != -1 && v.indexOf("command") != -1 &&
v.indexOf("keysExamined:") != -1 && v.indexOf("docsExamined:") != -1 &&
v.indexOf("SENTINEL") != -1;
}));
}