summaryrefslogtreecommitdiff
path: root/jstests/replsets/drop_collections_two_phase_drop_index.js
blob: f7360b52d0b286ab2eb040f9e37e8245fbf60636 (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
/**
 * Test to ensure that dropIndexes fails on a drop-pending collection.
 * @tags: [
 *     multiversion_incompatible,
 * ]
 */

(function() {
"use strict";

load("jstests/replsets/libs/two_phase_drops.js");  // For TwoPhaseDropCollectionTest.

// Set up a two phase drop test.
let testName = "drop_collection_two_phase";
let dbName = testName;
let collName = "collToDrop";
let twoPhaseDropTest = new TwoPhaseDropCollectionTest(testName, dbName);

// Initialize replica set.
let replTest = twoPhaseDropTest.initReplSet();

// Check for 'system.drop' two phase drop support.
if (!twoPhaseDropTest.supportsDropPendingNamespaces()) {
    jsTestLog('Drop pending namespaces not supported by storage engine. Skipping test.');
    twoPhaseDropTest.stop();
    return;
}

const primary = replTest.getPrimary();
const testDB = primary.getDB(dbName);
const coll = testDB.getCollection(collName);

// Create the collection that will be dropped.
twoPhaseDropTest.createCollection(collName);

assert.commandWorked(coll.createIndex({a: 1}));

try {
    // PREPARE collection drop.
    const dropPendingCollName = twoPhaseDropTest.prepareDropCollection(collName);

    const dropPendingColl = testDB.getCollection(dropPendingCollName);
    assert.commandFailedWithCode(dropPendingColl.dropIndex({a: 1}), ErrorCodes.NamespaceNotFound);
} finally {
    // COMMIT collection drop.
    twoPhaseDropTest.commitDropCollection(collName);
}

twoPhaseDropTest.stop();
}());