summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/txns/noop_createIndexes_not_blocked_by_txn.js62
1 files changed, 38 insertions, 24 deletions
diff --git a/jstests/core/txns/noop_createIndexes_not_blocked_by_txn.js b/jstests/core/txns/noop_createIndexes_not_blocked_by_txn.js
index 675db8b65f3..8caa0a65450 100644
--- a/jstests/core/txns/noop_createIndexes_not_blocked_by_txn.js
+++ b/jstests/core/txns/noop_createIndexes_not_blocked_by_txn.js
@@ -3,6 +3,10 @@
(function() {
"use strict";
+// TODO(SERVER-39704): Remove the following load after SERVER-39704 is completed
+// For withTxnAndAutoRetryOnMongos.
+load('jstests/libs/auto_retry_transaction_in_sharding.js');
+
const dbName = 'noop_createIndexes_not_blocked';
const collName = 'test';
const testDB = db.getSiblingDB(dbName);
@@ -24,33 +28,43 @@ const createIndexesCommand = {
};
assert.commandWorked(sessionDB.runCommand(createIndexesCommand));
-session.startTransaction();
-assert.commandWorked(sessionDB[collName].insert({a: 5, b: 6}));
+// Default read concern level to use for transactions. Snapshot read concern is not supported in
+// sharded transactions when majority reads are disabled.
+if (!TestData.hasOwnProperty('defaultTransactionReadConcernLevel')) {
+ TestData.defaultTransactionReadConcernLevel =
+ TestData.enableMajorityReadConcern !== false ? 'snapshot' : 'local';
+}
-// This should not block because an identical index exists.
-let res = testDB.runCommand(createIndexesCommand);
-assert.commandWorked(res);
-assert.eq(res.numIndexesBefore, res.numIndexesAfter);
+// TODO(SERVER-39704): We use the withTxnAndAutoRetryOnMongos
+// function to handle how MongoS will propagate a StaleShardVersion error as a
+// TransientTransactionError. After SERVER-39704 is completed the
+// withTxnAndAutoRetryOnMongos function can be removed
+withTxnAndAutoRetryOnMongos(session, () => {
+ assert.commandWorked(sessionDB[collName].insert({a: 5, b: 6}));
-// This should not block but return an error because the index exists with different options.
-res = testDB.runCommand({
- createIndexes: collName,
- indexes: [{key: {a: 1}, name: "unique_a_1", unique: true}],
-});
-assert.commandFailedWithCode(res, ErrorCodes.IndexOptionsConflict);
+ // This should not block because an identical index exists.
+ let res = testDB.runCommand(createIndexesCommand);
+ assert.commandWorked(res);
+ assert.eq(res.numIndexesBefore, res.numIndexesAfter);
-// This should block and time out because the index does not already exist.
-res = testDB.runCommand(
- {createIndexes: collName, indexes: [{key: {b: 1}, name: "b_1"}], maxTimeMS: 500});
-assert.commandFailedWithCode(res, ErrorCodes.MaxTimeMSExpired);
+ // This should not block but return an error because the index exists with different options.
+ res = testDB.runCommand({
+ createIndexes: collName,
+ indexes: [{key: {a: 1}, name: "unique_a_1", unique: true}],
+ });
+ assert.commandFailedWithCode(res, ErrorCodes.IndexOptionsConflict);
-// This should block and time out because one of the indexes does not already exist.
-res = testDB.runCommand({
- createIndexes: collName,
- indexes: [{key: {a: 1}, name: "a_1"}, {key: {b: 1}, name: "b_1"}],
- maxTimeMS: 500
-});
-assert.commandFailedWithCode(res, ErrorCodes.MaxTimeMSExpired);
+ // This should block and time out because the index does not already exist.
+ res = testDB.runCommand(
+ {createIndexes: collName, indexes: [{key: {b: 1}, name: "b_1"}], maxTimeMS: 500});
+ assert.commandFailedWithCode(res, ErrorCodes.MaxTimeMSExpired);
-assert.commandWorked(session.commitTransaction_forTesting());
+ // This should block and time out because one of the indexes does not already exist.
+ res = testDB.runCommand({
+ createIndexes: collName,
+ indexes: [{key: {a: 1}, name: "a_1"}, {key: {b: 1}, name: "b_1"}],
+ maxTimeMS: 500
+ });
+ assert.commandFailedWithCode(res, ErrorCodes.MaxTimeMSExpired);
+});
}());