summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/pbwm_max_time_ms.js
blob: 3f6d4961ad0c83f902ec5ee6668b9aecf90f2dee (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
/**
 * Tests that ParallelBatchWriterMode lock respects maxTimeMS.
 */
(function() {
"use strict";
load("jstests/libs/wait_for_command.js");

const conn = MongoRunner.runMongod();
let db = conn.getDB("test");

let lockPBWM = startParallelShell(() => {
    assert.commandFailedWithCode(db.adminCommand({
        sleep: 1,
        secs: 60 * 60,
        lockTarget: "ParallelBatchWriterMode",
        $comment: "PBWM lock sleep"
    }),
                                 ErrorCodes.Interrupted);
}, conn.port);

jsTestLog("Wait for that command to appear in currentOp");
const readID = waitForCommand(
    "PBWM lock", op => (op["command"]["$comment"] == "PBWM lock sleep"), conn.getDB("admin"));

jsTestLog("Operation that takes PBWM lock should timeout");
assert.commandFailedWithCode(db.a.runCommand({insert: "a", documents: [{x: 1}], maxTimeMS: 10}),
                             ErrorCodes.MaxTimeMSExpired);

jsTestLog("Kill the sleep command");
assert.commandWorked(db.killOp(readID));

jsTestLog("Wait for sleep command to finish");
lockPBWM();

MongoRunner.stopMongod(conn);
})();