summaryrefslogtreecommitdiff
path: root/jstests/core/profile_list_collections.js
blob: cf6132e71c74fd25b0a37e39f81929d2b1cd9da6 (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
// @tags: [does_not_support_stepdowns, requires_getmore, requires_profiling]

// Confirms that a listCollections command is not profiled.

(function() {
"use strict";

// For getLatestProfilerEntry and getProfilerProtocolStringForCommand.
load("jstests/libs/profiler.js");

var testDB = db.getSiblingDB("profile_list_collections");
assert.commandWorked(testDB.dropDatabase());
const numCollections = 5;
for (let i = 0; i < numCollections; ++i) {
    assert.commandWorked(testDB.runCommand({create: "test_" + i}));
}

testDB.setProfilingLevel(2);

const profileEntryFilter = {
    op: "command",
    command: "listCollections"
};

let cmdRes = assert.commandWorked(testDB.runCommand({listCollections: 1, cursor: {batchSize: 1}}));

// We don't profile listCollections commands.
assert.eq(testDB.system.profile.find(profileEntryFilter).itcount(),
          0,
          "Did not expect any profile entry for a listCollections command");

const getMoreCollName = cmdRes.cursor.ns.substr(cmdRes.cursor.ns.indexOf(".") + 1);
cmdRes = assert.commandWorked(
    testDB.runCommand({getMore: cmdRes.cursor.id, collection: getMoreCollName}));

// A listCollections cursor doesn't really have a namespace to use to record profile entries, so
// does not get recorded in the profile.
assert.throws(() => getLatestProfilerEntry(testDB, {op: "getmore"}),
              [],
              "Did not expect to find entry for getMore on a listCollections cursor");
})();