summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/write_conflict_wildcard.js
blob: ae2fcca5fc434f3da4840dad75eb0571c591b17e (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
/**
 * Tests that wildcard indexes are prepared to handle and retry WriteConflictExceptions while
 * interacting with the storage layer to retrieve multikey paths.
 */
(function() {
"strict";

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

const coll = testDB.write_conflict_wildcard;
coll.drop();

assert.commandWorked(coll.createIndex({"$**": 1}));

assert.commandWorked(testDB.adminCommand(
    {configureFailPoint: 'WTWriteConflictExceptionForReads', mode: {activationProbability: 0.01}}));
for (let i = 0; i < 1000; ++i) {
    // Insert documents with a couple different multikey paths to increase the number of records
    // scanned during multikey path computation in the wildcard index.
    assert.commandWorked(coll.insert({
        _id: i,
        i: i,
        a: [{x: i - 1}, {x: i}, {x: i + 1}],
        b: [],
        longerName: [{nested: [1, 2]}, {nested: 4}]
    }));
    assert.eq(coll.find({i: i}).hint({"$**": 1}).itcount(), 1);
    if (i > 0) {
        assert.eq(coll.find({"a.x": i}).hint({"$**": 1}).itcount(), 2);
    }
}

assert.commandWorked(
    testDB.adminCommand({configureFailPoint: 'WTWriteConflictExceptionForReads', mode: "off"}));
MongoRunner.stopMongod(conn);
})();