summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/coll_mod_takes_collection_x_lock.js
blob: 676078864d6dd3f5af377e94f0f44436fb4a09e1 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
 * Ensures that the 'collMod' command takes a Collection MODE_X lock during a no-op.
 */
(function() {
'use strict';

load('jstests/libs/parallel_shell_helpers.js');

// Note: failpoint name may not be changed due to backwards compatibility problem in
// multiversion suites running JS tests using the failpoint.
// In reality this hangs after acquiring a collection MODE_X lock (w/ database MODE_IX)."
const failpoint = 'hangAfterDatabaseLock';
assert.commandWorked(db.adminCommand({configureFailPoint: failpoint, mode: "alwaysOn"}));

const collectionName = jsTestName();

const conn = db.getMongo();
const coll = db.getCollection(collectionName);
coll.drop();
assert.commandWorked(db.createCollection(collectionName));

// Run a no-op collMod command.
const awaitParallelShell =
    startParallelShell(funWithArgs((collectionName) => {
                           assert.commandWorked(db.runCommand({collMod: collectionName}));
                       }, collectionName), conn.port);

// Check that the Collection MODE_X lock is being held by checking in lockInfo.
assert.soon(() => {
    let lockInfo = assert.commandWorked(db.adminCommand({lockInfo: 1})).lockInfo;
    for (let i = 0; i < lockInfo.length; i++) {
        let resourceId = lockInfo[i].resourceId;
        const mode = lockInfo[i].granted[0].mode;
        if (resourceId.includes("Collection") && resourceId.includes("test." + collectionName) &&
            mode === "X") {
            return true;
        }
    }

    return false;
});

assert.commandWorked(db.adminCommand({configureFailPoint: failpoint, mode: "off"}));
awaitParallelShell();
})();