summaryrefslogtreecommitdiff
path: root/jstests/core/catalog/list_indexes_invalidation.js
blob: 74afd3327bd22b7e73021aa71fb8c2f6a1495359 (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
// Cannot implicitly shard accessed collections because renameCollection command not supported
// on sharded collections.
// @tags: [
//   assumes_unsharded_collection,
//   requires_non_retryable_commands,
//   requires_fastcount,
//   requires_getmore
// ]

(function() {
'use strict';
let collName = 'system_indexes_invalidations';
let collNameRenamed = 'renamed_collection';
let coll = db[collName];
let collRenamed = db[collNameRenamed];

function testIndexInvalidation(isRename) {
    coll.drop();
    collRenamed.drop();
    assert.commandWorked(coll.createIndexes([{a: 1}, {b: 1}, {c: 1}]));

    // Get the first two indexes.
    let cmd = {listIndexes: collName};
    Object.extend(cmd, {cursor: {batchSize: 2}});
    let res = db.runCommand(cmd);
    assert.commandWorked(res, 'could not run ' + tojson(cmd));
    printjson(res);

    // Ensure the cursor has data, rename or drop the collection, and exhaust the cursor.
    let cursor = new DBCommandCursor(db, res);
    let errMsg = 'expected more data from command ' + tojson(cmd) + ', with result ' + tojson(res);
    assert(cursor.hasNext(), errMsg);
    assert(res.cursor.id !== NumberLong("0"), errMsg);
    if (isRename) {
        assert.commandWorked(coll.renameCollection(collNameRenamed));
    } else {
        assert(coll.drop());
    }
    assert.gt(cursor.itcount(), 0, errMsg);
}

// Test that we invalidate indexes for both collection drops and renames.
testIndexInvalidation(false);
testIndexInvalidation(true);
}());