summaryrefslogtreecommitdiff
path: root/jstests/core/currentop.js
diff options
context:
space:
mode:
authorCharlie Swanson <cswanson310@gmail.com>2016-12-07 08:33:46 -0500
committerCharlie Swanson <cswanson310@gmail.com>2016-12-07 12:07:20 -0500
commit0bca5d9fc70fe4178441eaf097324e6da814410a (patch)
treeb1ebad6bf389c54e5fdc9c7c6595b2dfefe7cee7 /jstests/core/currentop.js
parentd5024d5e0ca6cbb883a4ec65c5c76614bbdbbd53 (diff)
downloadmongo-0bca5d9fc70fe4178441eaf097324e6da814410a.tar.gz
SERVER-27042 Stabilize currentop.js and add unit tests for lock state reporting
Diffstat (limited to 'jstests/core/currentop.js')
-rw-r--r--jstests/core/currentop.js115
1 files changed, 33 insertions, 82 deletions
diff --git a/jstests/core/currentop.js b/jstests/core/currentop.js
index ef948d415be..d1e360c12c0 100644
--- a/jstests/core/currentop.js
+++ b/jstests/core/currentop.js
@@ -1,82 +1,33 @@
-print("BEGIN currentop.js");
-
-// test basic currentop functionality + querying of nested documents
-t = db.jstests_currentop;
-t.drop();
-
-for (i = 0; i < 100; i++) {
- t.save({"num": i});
-}
-
-print("count:" + t.count());
-
-function ops(q) {
- printjson(db.currentOp().inprog);
- return db.currentOp(q).inprog;
-}
-
-print("start shell");
-
-// 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); } } )");
-
-print("sleep");
-sleep(1000);
-
-print("inprog:");
-printjson(db.currentOp().inprog);
-print();
-sleep(1);
-print("inprog:");
-printjson(db.currentOp().inprog);
-print();
-
-// need to wait for read to start
-print("wait have some ops");
-assert.soon(function() {
- return ops({"locks.Collection": "r", "ns": "test.jstests_currentop"}).length +
- ops({"locks.Collection": "R", "ns": "test.jstests_currentop"}).length >=
- 1;
-}, "have_some_ops");
-print("ok");
-
-s2 = startParallelShell("db.jstests_currentop.update({ '$where': function() { sleep(150); } }," +
- " { '$inc': {num: 1} }, false, true );");
-
-o = [];
-
-function f() {
- o = ops({"ns": "test.jstests_currentop"});
-
- printjson(o);
-
- var writes = ops({"locks.Collection": "w", "ns": "test.jstests_currentop"}).length;
-
- var readops = ops({"locks.Collection": "r", "ns": "test.jstests_currentop"});
- print("readops:");
- printjson(readops);
- var reads = readops.length;
-
- print("total: " + o.length + " w: " + writes + " r:" + reads);
-
- return o.length > writes && o.length > reads;
-}
-
-print("go");
-
-assert.soon(f, "f");
-
-// avoid waiting for the operations to complete (if soon succeeded)
-for (var i in o) {
- db.killOp(o[i].opid);
-}
-
-start = new Date();
-
-// The operations running in the parallel shells may or may not have been killed.
-s1({checkExitSuccess: false});
-s2({checkExitSuccess: false});
-
-// don't want to pass if timeout killed the js function
-assert((new Date()) - start < 30000);
+/**
+ * Tests that long-running operations show up in currentOp and report the locks they are holding.
+ */
+(function() {
+ "use strict";
+ const coll = db.jstests_currentop;
+ coll.drop();
+
+ // We fsync+lock the server to cause all subsequent write operations to block.
+ assert.commandWorked(db.fsyncLock());
+
+ const awaitInsertShell = startParallelShell(function() {
+ assert.writeOK(db.jstests_currentop.insert({}));
+ });
+
+ // Wait until the write appears in the currentOp output reporting that it is waiting for a lock.
+ assert.soon(
+ function() {
+ return db.currentOp({
+ ns: coll.getFullName(),
+ "locks.Global": "w",
+ "waitingForLock": true,
+ }).inprog.length === 1;
+ },
+ function() {
+ return "Failed to find blocked insert in currentOp() output: " + tojson(db.currentOp());
+ });
+
+ // Unlock the server and make sure the write finishes.
+ const fsyncResponse = assert.commandWorked(db.fsyncUnlock());
+ assert.eq(fsyncResponse.lockCount, 0);
+ awaitInsertShell();
+}());