diff options
author | Brandon Diamond <brandon@10gen.com> | 2011-11-07 18:06:06 -0500 |
---|---|---|
committer | Brandon Diamond <brandon@10gen.com> | 2011-11-07 18:09:31 -0500 |
commit | c5b1fd158175de59c5b454312328a9dfb2aefe5a (patch) | |
tree | 027857893a6d9a41906b6a2f9b9722c25f6741ca /jstests/currentop.js | |
parent | fe671eb75a2e017259b13a328f4ecfbffff73e3e (diff) | |
download | mongo-c5b1fd158175de59c5b454312328a9dfb2aefe5a.tar.gz |
SERVER-2663: Added testcase
Diffstat (limited to 'jstests/currentop.js')
-rw-r--r-- | jstests/currentop.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/jstests/currentop.js b/jstests/currentop.js new file mode 100644 index 00000000000..d1b9fb65144 --- /dev/null +++ b/jstests/currentop.js @@ -0,0 +1,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({}); + + var writes = ops({ "lockType": "write" }).length; + var reads = ops({ "lockType": "read" }).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 ); |