summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuhong Zhang <danielzhangyh@gmail.com>2021-07-01 18:49:22 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-07-20 03:22:25 +0000
commit0b73de2892501d3569f13bb7e375e29f902884a7 (patch)
tree06dbc2691375bd78c6b1ffa5ffe589ebd34bdb94
parentdcbda6e6b325c2fc047c8cce06cafc2d7f48f045 (diff)
downloadmongo-0b73de2892501d3569f13bb7e375e29f902884a7.tar.gz
SERVER-50287 drop_index.js fails when run in passthrough suite with stepdown
(cherry picked from commit d8170c86a9b14687ca93df4e18241f05d058f780)
-rw-r--r--jstests/core/drop_index.js25
-rw-r--r--jstests/core/drop_indexes.js64
2 files changed, 67 insertions, 22 deletions
diff --git a/jstests/core/drop_index.js b/jstests/core/drop_index.js
index 60dbec0e3ea..3083242270f 100644
--- a/jstests/core/drop_index.js
+++ b/jstests/core/drop_index.js
@@ -61,26 +61,7 @@ assert.commandFailedWithCode(t.dropIndex({_id: 1}), ErrorCodes.InvalidOptions);
assert.commandWorked(t.createIndex({a: 1}));
assertIndexes(['a_1', 'c_1', 'd_1', 'e_1'], 'recreating {a: 1}');
-// Drop multiple indexes.
-assert.commandWorked(t.dropIndexes(['c_1', 'd_1']));
-assertIndexes(['a_1', 'e_1'], 'dropping {c: 1} and {d: 1}');
-
-// Must drop all the indexes provided or none at all - for example, if one of the index names
-// provided is invalid.
-let ex = assert.throws(() => {
- t.dropIndexes(['a_1', '_id_']);
-});
-assert.commandFailedWithCode(ex, ErrorCodes.InvalidOptions);
-assertIndexes(['a_1', 'e_1'], 'failed dropIndexes command with _id index');
-
-// List of index names must contain only strings.
-ex = assert.throws(() => {
- t.dropIndexes(['a_1', 123]);
-});
-assert.commandFailedWithCode(ex, ErrorCodes.TypeMismatch);
-assertIndexes(['a_1', 'e_1'], 'failed dropIndexes command with non-string index name');
-
-// Drop all indexes.
-assert.commandWorked(t.dropIndexes());
-assertIndexes([], 'dropping all indexes');
+// Drop single index with dropIndexes().
+assert.commandWorked(t.dropIndexes(['c_1']));
+assertIndexes(['a_1', 'd_1', 'e_1'], 'dropping {c: 1}');
}());
diff --git a/jstests/core/drop_indexes.js b/jstests/core/drop_indexes.js
new file mode 100644
index 00000000000..8250d267980
--- /dev/null
+++ b/jstests/core/drop_indexes.js
@@ -0,0 +1,64 @@
+// Cannot implicitly shard accessed collections because of extra shard key index in sharded
+// collection. Cannot be handled correctly in a stepdown suite since dropIndexes() with multiple
+// names cannot be retried properly.
+// @tags: [assumes_no_implicit_index_creation, does_not_support_stepdowns]
+(function() {
+'use strict';
+
+const t = db.drop_indexes;
+t.drop();
+
+/**
+ * Extracts index names from listIndexes result.
+ */
+function getIndexNames(cmdRes) {
+ return t.getIndexes().map(spec => spec.name);
+}
+
+/**
+ * Checks that collection contains the given list of non-id indexes and nothing else.
+ */
+function assertIndexes(expectedIndexNames, msg) {
+ const actualIndexNames = getIndexNames();
+ const testMsgSuffix = () => msg + ': expected ' + tojson(expectedIndexNames) + ' but got ' +
+ tojson(actualIndexNames) + ' instead.';
+ assert.eq(expectedIndexNames.length + 1,
+ actualIndexNames.length,
+ 'unexpected number of indexes after ' + testMsgSuffix());
+ assert(actualIndexNames.includes('_id_'),
+ '_id index missing after ' + msg + ': ' + tojson(actualIndexNames));
+ for (let expectedIndexName of expectedIndexNames) {
+ assert(actualIndexNames.includes(expectedIndexName),
+ expectedIndexName + ' index missing after ' + testMsgSuffix());
+ }
+}
+
+assert.commandWorked(t.insert({_id: 1, a: 2, b: 3, c: 1, d: 1, e: 1}));
+assertIndexes([], 'inserting test document');
+
+assert.commandWorked(t.createIndex({a: 1}));
+assert.commandWorked(t.createIndex({b: 1}));
+assert.commandWorked(t.createIndex({c: 1}));
+assert.commandWorked(t.createIndex({d: 1}));
+assert.commandWorked(t.createIndex({e: 1}));
+assertIndexes(['a_1', 'b_1', 'c_1', 'd_1', 'e_1'], 'creating indexes');
+
+// Drop multiple indexes.
+assert.commandWorked(t.dropIndexes(['c_1', 'd_1']));
+assertIndexes(['a_1', 'b_1', 'e_1'], 'dropping {c: 1} and {d: 1}');
+
+// Must drop all the indexes provided or none at all - for example, if one of the index names
+// provided is invalid.
+let ex = assert.throws(() => {
+ t.dropIndexes(['a_1', '_id_']);
+});
+assert.commandFailedWithCode(ex, ErrorCodes.InvalidOptions);
+assertIndexes(['a_1', 'b_1', 'e_1'], 'failed dropIndexes command with _id index');
+
+// List of index names must contain only strings.
+ex = assert.throws(() => {
+ t.dropIndexes(['a_1', 123]);
+});
+assert.commandFailedWithCode(ex, ErrorCodes.TypeMismatch);
+assertIndexes(['a_1', 'b_1', 'e_1'], 'failed dropIndexes command with non-string index name');
+}());