summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorCharlie Swanson <cswanson310@gmail.com>2016-12-07 08:33:46 -0500
committerCharlie Swanson <charlie.swanson@mongodb.com>2016-12-12 18:00:55 -0500
commit9d920663421437e65706b0587077781895984e2d (patch)
tree5d83afaba605e8520e19a08992b7eec53e8296db /jstests
parentb25817dde10af84b7a9b0721bae294c043360f64 (diff)
downloadmongo-9d920663421437e65706b0587077781895984e2d.tar.gz
SERVER-27042 Stabilize currentop.js and add unit tests for lock state reporting
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/currentop.js114
-rw-r--r--jstests/libs/parallelTester.js4
2 files changed, 34 insertions, 84 deletions
diff --git a/jstests/core/currentop.js b/jstests/core/currentop.js
index ef948d415be..296ad69355c 100644
--- a/jstests/core/currentop.js
+++ b/jstests/core/currentop.js
@@ -1,82 +1,32 @@
-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.
+ assert.commandWorked(db.fsyncUnlock());
+ awaitInsertShell();
+}());
diff --git a/jstests/libs/parallelTester.js b/jstests/libs/parallelTester.js
index b043e3de78d..0126bfad9c3 100644
--- a/jstests/libs/parallelTester.js
+++ b/jstests/libs/parallelTester.js
@@ -149,7 +149,6 @@ if (typeof _threadInject != "undefined") {
// this has a chance to see the message
"connections_opened.js", // counts connections, globally
"opcounters_write_cmd.js",
- "currentop.js", // SERVER-8673, plus rwlock yielding issues
"set_param1.js", // changes global state
"geo_update_btree2.js", // SERVER-11132 test disables table scans
"update_setOnInsert.js", // SERVER-9982
@@ -168,8 +167,9 @@ if (typeof _threadInject != "undefined") {
// some tests can't be run in parallel with each other
var serialTestsArr = [
+ // These tests use fsyncLock.
parallelFilesDir + "/fsync.js",
- parallelFilesDir + "/auth1.js",
+ parallelFilesDir + "/currentop.js",
// These tests expect the profiler to be on or off at specific points
// during the test run.