summaryrefslogtreecommitdiff
path: root/jstests/core/currentop.js
blob: 296ad69355cacfb7decfc62717a6d22239b30895 (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
/**
 * 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();
}());