summaryrefslogtreecommitdiff
path: root/jstests/replsets/profile.js
blob: 4ff7a6e4ebe536a48851c1bdb424430a40227986 (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
// Confirm that implicitly created profile collections are successful and do not trigger assertions.
// In order to implicitly create a profile collection with a read, we must set up the server with
// some data to read without the profiler being active.
// @tags: [requires_persistence]
(function() {
"use strict";
let rst = new ReplSetTest({nodes: {n0: {profile: "0"}}});
rst.startSet();
rst.initiate();
let primary = rst.getPrimary();
let primaryDB = primary.getDB('test');

assert.commandWorked(primaryDB.foo.insert({_id: 1}));

const nodeId = rst.getNodeId(primary);
rst.stop(nodeId);
rst.start(nodeId, {profile: "2"}, true /* preserves data directory */);
rst.awaitReplication();
primary = rst.getPrimary();
primaryDB = primary.getDB('test');

let oldAssertCounts = primaryDB.serverStatus().asserts;
jsTestLog('Before running aggregation: Assert counts reported by db.serverStatus(): ' +
          tojson(oldAssertCounts));
primaryDB.setLogLevel(1, 'assert');
try {
    assert.eq(0, primaryDB.system.profile.count());
    assert.eq([{_id: 1}], primaryDB.foo.aggregate([]).toArray());

    let newAssertCounts = primaryDB.serverStatus().asserts;
    jsTestLog('After running aggregation: Assert counts reported by db.serverStatus(): ' +
              tojson(newAssertCounts));
    assert.eq(oldAssertCounts, newAssertCounts);
    // Should have 2 entries, one for the count command and one for the aggregate command.
    assert.eq(2, primaryDB.system.profile.count());
} finally {
    primaryDB.setLogLevel(0, 'assert');
}

rst.stopSet();
})();