summaryrefslogtreecommitdiff
path: root/jstests/profile1.js
blob: 0e8009a7e0409a7409c0e9128f9382cf6ae957ad (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

try {

/* With pre-created system.profile (capped) */
db.runCommand({profile: 0});
db.getCollection("system.profile").drop();
assert(!db.getLastError(), "Z");
assert.eq(0, db.runCommand({profile: -1}).was, "A");

db.createCollection("system.profile", {capped: true, size: 1000});
db.runCommand({profile: 2});
assert.eq(2, db.runCommand({profile: -1}).was, "B");
assert.eq(1, db.system.profile.stats().capped, "C");
var capped_size = db.system.profile.storageSize();
assert.gt(capped_size, 999, "D");
assert.lt(capped_size, 2000, "E");

db.foo.findOne()

assert.eq( 4 , db.system.profile.find().count() , "E2" );

/* Make sure we can't drop if profiling is still on */
assert.throws( function(z){ db.getCollection("system.profile").drop(); } )

/* With pre-created system.profile (un-capped) */
db.runCommand({profile: 0});
db.getCollection("system.profile").drop();
assert.eq(0, db.runCommand({profile: -1}).was, "F");

db.createCollection("system.profile");
db.runCommand({profile: 2});
assert.eq(2, db.runCommand({profile: -1}).was, "G");
assert.eq(null, db.system.profile.stats().capped, "G1");

/* With no system.profile collection */
db.runCommand({profile: 0});
db.getCollection("system.profile").drop();
assert.eq(0, db.runCommand({profile: -1}).was, "H");

db.runCommand({profile: 2});
assert.eq(2, db.runCommand({profile: -1}).was, "I");
assert.eq(1, db.system.profile.stats().capped, "J");
var auto_size = db.system.profile.storageSize();
assert.gt(auto_size, capped_size, "K");

} finally {
    // disable profiling for subsequent tests
    assert.commandWorked( db.runCommand( {profile:0} ) );
}