summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/list_indexes_ready_and_in_progress.js
blob: a1970beea83168280a66584dfda6c9af5d85333f (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
/**
 * Tests that the listIndexes command shows ready and in-progress indexes.
 */
(function() {
"use strict";

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

const conn = MongoRunner.runMongod();
assert.neq(null, conn, "mongod was unable to start up");

const testDB = conn.getDB("test");
assert.commandWorked(testDB.dropDatabase());

let coll = testDB.list_indexes_ready_and_in_progress;
coll.drop();
assert.commandWorked(testDB.createCollection(coll.getName()));
IndexBuildTest.assertIndexes(coll, 1, ["_id_"]);
assert.commandWorked(coll.createIndex({a: 1}));
IndexBuildTest.assertIndexes(coll, 2, ["_id_", "a_1"]);

IndexBuildTest.pauseIndexBuilds(conn);
const createIdx =
    IndexBuildTest.startIndexBuild(conn, coll.getFullName(), {b: 1}, {background: true});
IndexBuildTest.waitForIndexBuildToStart(testDB);

// The listIndexes command supports returning all indexes, including ones that are not ready.
IndexBuildTest.assertIndexes(coll, 3, ["_id_", "a_1"], ["b_1"], {includeBuildUUIDs: true});

IndexBuildTest.resumeIndexBuilds(conn);

// Wait for the index build to stop.
IndexBuildTest.waitForIndexBuildToStop(testDB);

const exitCode = createIdx();
assert.eq(0, exitCode, 'expected shell to exit cleanly');

IndexBuildTest.assertIndexes(coll, 3, ["_id_", "a_1", "b_1"]);
MongoRunner.stopMongod(conn);
}());