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 86 87 88 89 90 91 92 93 94 95 96 97
|
// Check debug information recorded for a query.
// special db so that it can be run in parallel tests
var stddb = db;
var db = db.getSisterDB("profile4");
t = db.profile4;
t.drop();
function profileCursor() {
return db.system.profile.find( { user:username + "@" + db.getName() } );
}
function lastOp() {
p = profileCursor().sort( { $natural:-1 } ).next();
// printjson( p );
return p;
}
function checkLastOp( spec ) {
p = lastOp();
for( i in spec ) {
s = spec[ i ];
assert.eq( s[ 1 ], p[ s[ 0 ] ], s[ 0 ] );
}
}
try {
username = "jstests_profile4_user";
db.addUser( username, "password", false, 1 );
db.auth( username, "password" );
db.setProfilingLevel(0);
db.system.profile.drop();
assert.eq( 0 , profileCursor().count() )
db.setProfilingLevel(2);
t.find().itcount();
checkLastOp( [ [ "op", "query" ],
[ "ns", "profile4.profile4" ],
[ "query", {} ],
[ "ntoreturn", 0 ],
[ "ntoskip", 0 ],
[ "nscanned", 0 ],
[ "keyUpdates", 0 ],
[ "nreturned", 0 ],
[ "responseLength", 20 ] ] );
t.save( {} );
// check write lock stats are set
o = lastOp();
assert.eq('insert', o.op);
assert.eq( 0, o.lockStats.timeLockedMicros.r );
assert.lt( 0, o.lockStats.timeLockedMicros.w );
assert.eq( 0, o.lockStats.timeAcquiringMicros.r );
//assert.lt( 0, o.lockStats.timeAcquiringMicros.w ); // Removed due to SERVER-8331
// check read lock stats are set
t.find();
o = lastOp();
assert.eq('query', o.op);
assert.lt( 0, o.lockStats.timeLockedMicros.r );
assert.eq( 0, o.lockStats.timeLockedMicros.w );
//assert.lt( 0, o.lockStats.timeAcquiringMicros.r ); // Removed due to SERVER-8331
//assert.lt( 0, o.lockStats.timeAcquiringMicros.w ); // Removed due to SERVER-8331
t.save( {} );
t.save( {} );
t.find().skip( 1 ).limit( 4 ).itcount();
checkLastOp( [ [ "ntoreturn", 4 ],
[ "ntoskip", 1 ],
[ "nscanned", 3 ],
[ "nreturned", 2 ] ] );
t.find().batchSize( 2 ).next();
o = lastOp();
assert.lt( 0, o.cursorid );
t.find( {a:1} ).itcount();
checkLastOp( [ [ "query", {a:1} ] ] );
t.find( {_id:0} ).itcount();
checkLastOp( [ [ "idhack", true ] ] );
t.find().sort( {a:1} ).itcount();
checkLastOp( [ [ "scanAndOrder", true ] ] );
db.setProfilingLevel(0);
db.system.profile.drop();
}
finally {
db.setProfilingLevel(0);
db = stddb;
}
|