summaryrefslogtreecommitdiff
path: root/jstests/replsets/nested_apply_ops_create_indexes.js
blob: b3cd5843314b699669f9bacd90b75f4895d2829b (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
46
47
48
49
50
51
52
53
54
55
56
57
/**
 * Test createIndexes while recursively locked in a nested applyOps.
 */
(function() {
"use strict";

load('jstests/noPassthrough/libs/index_build.js');

let rst = new ReplSetTest({nodes: 3});
rst.startSet();
rst.initiate();

let collName = "col";
let dbName = "nested_apply_ops_create_indexes";

let primary = rst.getPrimary();
let primaryTestDB = primary.getDB(dbName);
let cmd = {"create": collName};
let res = primaryTestDB.runCommand(cmd);
assert.commandWorked(res, "could not run " + tojson(cmd));
rst.awaitReplication();

let uuid = primaryTestDB.getCollectionInfos()[0].info.uuid;
let cmdFormatIndexNameA = "a_1";
cmd = {
    applyOps: [{
        op: "c",
        ns: dbName + ".$cmd",
        ui: uuid,
        o: {
            applyOps: [{
                op: "c",
                ns: dbName + "." + collName,
                ui: uuid,
                o: {createIndexes: collName, v: 2, key: {a: 1}, name: cmdFormatIndexNameA}
            }]
        }
    }]
};
res = primaryTestDB.runCommand(cmd);

// It is not possible to test createIndexes in applyOps with two-phase-index-builds support because
// that command is not accepted by applyOps in that mode.
if (IndexBuildTest.supportsTwoPhaseIndexBuild(primary)) {
    assert.commandFailedWithCode(res, ErrorCodes.CommandNotSupported);
    rst.stopSet();
    return;
}

assert.commandWorked(res, "could not run " + tojson(cmd));
rst.awaitReplication();

const coll = primaryTestDB.getCollection(collName);
IndexBuildTest.assertIndexes(coll, 2, ['_id_', cmdFormatIndexNameA]);

rst.stopSet();
})();