summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/truncate_large_profiler_entry.js
blob: 15cdbee5e44fa7bfb84136d9c9a5a6cc65f31b37 (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
/**
 * Test which verifies that large profiler entries generated for SBE plans do not exceed the max
 * BSON depth. Instead, they get truncated right below the max depth.
 */
(function() {
"use strict";

const conn = MongoRunner.runMongod();
assert.neq(null, conn, "mongod was unable to startup");
const db = conn.getDB("test");
const collName = jsTestName();
const coll = db[collName];
coll.drop();

// Insert some documents so our query will perform some work.
assert.commandWorked(coll.insert([{a: 1}, {a: 2}]));
const longField = 'a.'.repeat(99) + 'a';
const projectionSpec = {
    [longField]: 1
};

// Setup the profiler to only pick up the query below.
assert.commandWorked(db.setProfilingLevel(2, {slowms: 0, sampleRate: 1}, {
    filter: {'op': 'query', 'command.projection': projectionSpec}
}));

// Verify that our query was picked up by the profiler.
coll.find({}, projectionSpec).toArray();
const profilerEntry = db.system.profile.find().toArray();
assert.eq(1, profilerEntry.length, profilerEntry);

// Collection validation should detect no issues.
assert.commandWorked(db.system.profile.validate({full: true}));
MongoRunner.stopMongod(conn);
}());