summaryrefslogtreecommitdiff
path: root/jstests/currentop.js
blob: 6c0868ec53d5f13d44afae59367e496b085db416 (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
// test basic currentop functionality + querying of nested documents
t = db.jstests_currentop
t.drop();

for(i=0;i<100;i++) {
    t.save({ "num": i });
}

function ops(q) {
    return db.currentOp(q).inprog;
}

// sleep for a second for each (of 100) documents; can be killed in between documents & test should complete before 100 seconds 
s1 = startParallelShell( "db.jstests_currentop.count( { '$where': function() { sleep(1000); } } )" );
s2 = startParallelShell( "db.jstests_currentop.update( { '$where': function() { sleep(1000); } }, { 'num': 1 }, false, true )" );

o = [];
assert.soon( function() {
    o = ops({ "ns": "test.jstests_currentop" });

    var writes = ops({ "lockType": "write", "ns": "test.jstests_currentop" }).length;
    var reads = ops({ "lockType": "read", "ns": "test.jstests_currentop" }).length;

    return o.length > writes && o.length > reads;
} );

// avoid waiting for the operations to complete (if soon succeeded)
for(var i in o) {
    db.killOp(o[i].opid);
}

start = new Date();

s1();
s2();

// don't want to pass if timeout killed the js function
assert( ( new Date() ) - start < 30000 );