summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/convert_to_capped_no_conflicts.js
blob: f037b0075ee0feb26c60e9b1edc136f2ec1b0433 (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
/**
 * Tests that convertToCapped does not conflict with a database MODE_IX lock.
 */
(function() {
"use strict";

load("jstests/libs/parallel_shell_helpers.js");
load("jstests/libs/wait_for_command.js");

const collName = "convert_to_capped_no_conflicts";
const testDB = db.getSiblingDB("test");
testDB.dropDatabase();
const testColl = testDB.getCollection(collName);

const sleepFunction = function(sleepDB) {
    // If convertToCapped calls need to wait on this lock, holding this lock for 4 hours will
    // trigger a test timeout.
    assert.commandFailedWithCode(
        db.getSiblingDB("test").adminCommand(
            {sleep: 1, secs: 18000, lockTarget: sleepDB, lock: "iw", $comment: "Lock sleep"}),
        ErrorCodes.Interrupted);
};

const sleepCommand = startParallelShell(funWithArgs(sleepFunction, "test"), testDB.getMongo().port);
const sleepID =
    waitForCommand("sleepCmd",
                   op => (op["ns"] == "admin.$cmd" && op["command"]["$comment"] == "Lock sleep"),
                   testDB.getSiblingDB("admin"));

assert.commandWorked(testColl.insert({a: 1}));
assert(!testColl.isCapped());
assert.commandWorked(testDB.runCommand({convertToCapped: collName, size: 1}));
assert(testColl.isCapped());

// Interrupt the sleep command.
assert.commandWorked(testDB.getSiblingDB("admin").killOp(sleepID));
sleepCommand();
})();