summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/dropindexes_duplicate_fields.js
blob: adc62c8f4d878f7cc78b8035fd3053d52432745c (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
/*
 * Test that dropIndexes does not return a message containing multiple "nIndexesWas" fields.
 *
 * @tags: [requires_wiredtiger]
 */

(function() {
"use strict";

let oldRes, newRes;
let coll = db.dropindexes_duplicate_fields;

try {
    // Repeat 100 times for the sake of probabilities
    for (let i = 0; i < 100; i++) {
        coll.drop();
        assert.commandWorked(coll.insert({x: 1}));
        assert.commandWorked(coll.createIndex({"x": 1}));

        assert.commandWorked(db.adminCommand(
            {configureFailPoint: 'WTWriteConflictException', mode: {activationProbability: 0.1}}));

        // Will blow up if writeConflictRetry causes duplicate fields to be appended to result
        let res = db.runCommand({dropIndexes: coll.getName(), index: {"x": 1}});
        if (!oldRes && !newRes) {
            oldRes = res;
        } else if (oldRes && !newRes) {
            newRes = res;
        } else {
            oldRes = newRes;
            newRes = res;
        }

        assert.commandWorked(newRes ? newRes : oldRes);

        // Responses between runs should be the same independent of a WriteConflict
        if (oldRes && newRes) {
            assert.eq(oldRes, newRes);
        }

        assert.commandWorked(
            db.adminCommand({configureFailPoint: 'WTWriteConflictException', mode: "off"}));
    }
} finally {
    assert.commandWorked(
        db.adminCommand({configureFailPoint: 'WTWriteConflictException', mode: "off"}));
}
})();