diff options
author | Charlie Swanson <cswanson310@gmail.com> | 2016-12-07 08:33:46 -0500 |
---|---|---|
committer | Charlie Swanson <cswanson310@gmail.com> | 2016-12-07 12:07:20 -0500 |
commit | 0bca5d9fc70fe4178441eaf097324e6da814410a (patch) | |
tree | b1ebad6bf389c54e5fdc9c7c6595b2dfefe7cee7 /jstests | |
parent | d5024d5e0ca6cbb883a4ec65c5c76614bbdbbd53 (diff) | |
download | mongo-0bca5d9fc70fe4178441eaf097324e6da814410a.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.js | 115 | ||||
-rw-r--r-- | jstests/core/fsync.js | 2 | ||||
-rw-r--r-- | jstests/libs/parallelTester.js | 6 |
3 files changed, 37 insertions, 86 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(); +}()); diff --git a/jstests/core/fsync.js b/jstests/core/fsync.js index 9f622867ee1..13ff20e4177 100644 --- a/jstests/core/fsync.js +++ b/jstests/core/fsync.js @@ -89,7 +89,7 @@ assert(fsyncPseudoCommandRes.ok, "fsyncUnlock pseudo-command failed"); assert(db.currentOp().fsyncLock == null, "fsyncUnlock is not null in db.currentOp"); - // Make sure that insert attempts made during multiple fsynLock requests will not execute until + // Make sure that insert attempts made during multiple fsyncLock requests will not execute until // all locks have been released. fsyncLockRes = db.fsyncLock(); assert.commandWorked(fsyncLockRes); diff --git a/jstests/libs/parallelTester.js b/jstests/libs/parallelTester.js index ca964d86111..d4d8f96d7b4 100644 --- a/jstests/libs/parallelTester.js +++ b/jstests/libs/parallelTester.js @@ -173,7 +173,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 @@ -192,11 +191,12 @@ 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. They should not - // be run in parallel with tests that peform fsyncLock. User operations skip writing to + // be run in parallel with tests that perform fsyncLock. User operations skip writing to // the system.profile collection while the server is fsyncLocked. // // The profiler tests can be run in parallel with each other as they use test-specific |