summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2020-04-16 18:00:39 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-04-16 22:12:44 +0000
commitf889e85da61e90586d032e8b706bf9506919f253 (patch)
tree3994aed3604048847b191397a785bb6dbfdd40f3 /jstests
parentd9d92a15561dc84223d302475e09d0fa91309550 (diff)
downloadmongo-f889e85da61e90586d032e8b706bf9506919f253.tar.gz
SERVER-45933 index builds support maxTimeMS through createIndexes interruptions
Diffstat (limited to 'jstests')
-rw-r--r--jstests/noPassthrough/index_max_time_ms.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/jstests/noPassthrough/index_max_time_ms.js b/jstests/noPassthrough/index_max_time_ms.js
new file mode 100644
index 00000000000..484521cc3de
--- /dev/null
+++ b/jstests/noPassthrough/index_max_time_ms.js
@@ -0,0 +1,70 @@
+/**
+ * Confirms that index builds on a primary are aborted when the createIndexes operation times out
+ * (based on expiration derived from maxTimeMS).
+ * @tags: [requires_replication]
+ */
+(function() {
+"use strict";
+
+load('jstests/noPassthrough/libs/index_build.js');
+
+const rst = new ReplSetTest({
+ nodes: [
+ {},
+ {
+ // Disallow elections on secondary.
+ rsConfig: {
+ priority: 0,
+ votes: 0,
+ },
+ },
+ ]
+});
+const nodes = rst.startSet();
+rst.initiate();
+
+const primary = rst.getPrimary();
+const testDB = primary.getDB('test');
+const coll = testDB.getCollection('test');
+
+assert.commandWorked(coll.insert({a: 1}));
+
+IndexBuildTest.pauseIndexBuilds(primary);
+
+const createIndexesCmd = {
+ createIndexes: coll.getName(),
+ indexes: [
+ {
+ name: 'a_1',
+ key: {a: 1},
+ },
+ ],
+ // This timeout value should be long enough for this test to locate the index build in the
+ // db.currentOp() output.
+ maxTimeMS: 10000,
+};
+
+const createIdx =
+ startParallelShell('assert.commandFailedWithCode(db.getSiblingDB("' + testDB.getName() +
+ '").runCommand(' + tojson(createIndexesCmd) + '), ' +
+ 'ErrorCodes.MaxTimeMSExpired' +
+ ');',
+ primary.port);
+
+try {
+ IndexBuildTest.waitForIndexBuildToScanCollection(testDB, coll.getName(), 'a_1');
+
+ // Index build will be interrupted when the createIndexes command times out.
+ IndexBuildTest.waitForIndexBuildToStop(testDB);
+} finally {
+ IndexBuildTest.resumeIndexBuilds(primary);
+}
+
+createIdx();
+
+// Check that no new index has been created. This verifies that the index build was aborted
+// rather than successfully completed.
+IndexBuildTest.assertIndexes(coll, 1, ['_id_']);
+
+rst.stopSet();
+})();