summaryrefslogtreecommitdiff
path: root/jstests/core/profile2.js
blob: f8f0040683e7f136f42c316cb37fe2f98347a33f (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Tests that large queries and updates are properly profiled.

// Special db so that it can be run in parallel tests.
// @tags: [requires_profiling]

var coll = db.getSisterDB("profile2").profile2;

assert.commandWorked(coll.getDB().runCommand({profile: 0}));
coll.drop();
coll.getDB().system.profile.drop();
assert.commandWorked(coll.getDB().runCommand({profile: 2}));

var str = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
var hugeStr = str;
while (hugeStr.length < 2 * 1024 * 1024) {
    hugeStr += str;
}

// Test query with large string element.
coll.find({a: hugeStr}).itcount();
var results = coll.getDB().system.profile.find().toArray();
assert.eq(1, results.length);
var result = results[0];
assert(result.hasOwnProperty('ns'));
assert(result.hasOwnProperty('millis'));
assert(result.hasOwnProperty('command'));
assert.eq('string', typeof (result.command.$truncated));
// String value is truncated.
assert(result.command.$truncated.match(/filter: { a: "a+\.\.\." }/));

assert.commandWorked(coll.getDB().runCommand({profile: 0}));
coll.getDB().system.profile.drop();
assert.commandWorked(coll.getDB().runCommand({profile: 2}));

// Test update with large string element in query portion.
assert.commandWorked(coll.update({a: hugeStr}, {}));
var results = coll.getDB().system.profile.find().toArray();
assert.eq(1, results.length);
var result = results[0];
assert(result.hasOwnProperty('ns'));
assert(result.hasOwnProperty('millis'));
assert(result.hasOwnProperty('command'));
assert.eq('string', typeof (result.command.$truncated));
// String value is truncated.
assert(result.command.$truncated.match(
    /^{ q: { a: "a+\.\.\." }, u: {}, multi: false, upsert: false }$/));

assert.commandWorked(coll.getDB().runCommand({profile: 0}));
coll.getDB().system.profile.drop();
assert.commandWorked(coll.getDB().runCommand({profile: 2}));

// Test update with large string element in update portion.
assert.commandWorked(coll.update({}, {a: hugeStr}));
var results = coll.getDB().system.profile.find().toArray();
assert.eq(1, results.length);
var result = results[0];
assert(result.hasOwnProperty('ns'));
assert(result.hasOwnProperty('millis'));
assert(result.hasOwnProperty('command'));
assert.eq('string', typeof (result.command.$truncated));
// String value is truncated.
assert(result.command.$truncated.match(
    /^{ q: {}, u: { a: "a+\.\.\." }, multi: false, upsert: false }$/));

assert.commandWorked(coll.getDB().runCommand({profile: 0}));
coll.getDB().system.profile.drop();
assert.commandWorked(coll.getDB().runCommand({profile: 2}));

// Test query with many elements in query portion.
var doc = {};
for (var i = 0; i < 100 * 1000; ++i) {
    doc["a" + i] = 1;
}
coll.find(doc).itcount();
var results = coll.getDB().system.profile.find().toArray();
assert.eq(1, results.length);
var result = results[0];
assert(result.hasOwnProperty('ns'));
assert(result.hasOwnProperty('millis'));
assert(result.hasOwnProperty('command'));
assert.eq('string', typeof (result.command.$truncated));
// Query object itself is truncated.
assert(result.command.$truncated.match(/filter: { a0: 1\.0, a1: .*\.\.\.$/));

assert.commandWorked(coll.getDB().runCommand({profile: 0}));