summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTommaso Tocci <tommaso.tocci@mongodb.com>2021-06-29 18:12:43 +0200
committerTommaso Tocci <tommaso.tocci@mongodb.com>2021-06-30 18:27:39 +0200
commit5bed5eb87281673fcbbde620033091437ba5db6b (patch)
tree83b40a27c286a84f6a167f963001b42220949805
parent24e800de037cb8e544ef3020c9fccedd7a44e9d9 (diff)
downloadmongo-5bed5eb87281673fcbbde620033091437ba5db6b.tar.gz
SERVER-58145 Handle stale config exception during txn in multi_update_in_transactions.js
(cherry picked from commit ea2e1a434118c9e93420d0564d229290425b18bd)
-rw-r--r--jstests/core/txns/multi_update_in_transaction.js111
1 files changed, 54 insertions, 57 deletions
diff --git a/jstests/core/txns/multi_update_in_transaction.js b/jstests/core/txns/multi_update_in_transaction.js
index d9754f586d8..311104679cd 100644
--- a/jstests/core/txns/multi_update_in_transaction.js
+++ b/jstests/core/txns/multi_update_in_transaction.js
@@ -3,6 +3,8 @@
(function() {
"use strict";
+load('jstests/libs/auto_retry_transaction_in_sharding.js');
+
const dbName = "test";
const collName = "multi_update_in_transaction";
const testDB = db.getSiblingDB(dbName);
@@ -23,70 +25,65 @@ jsTest.log("Prepopulate the collection.");
assert.commandWorked(testColl.insert([{_id: 0, a: 0}, {_id: 1, a: 0}, {_id: 2, a: 1}],
{writeConcern: {w: "majority"}}));
-jsTest.log("Do an empty multi-update.");
-session.startTransaction({writeConcern: {w: "majority"}});
-
-// Update 0 docs.
-let res = sessionColl.update({a: 99}, {$set: {b: 1}}, {multi: true});
-assert.eq(0, res.nModified);
-res = sessionColl.find({});
-assert.sameMembers(res.toArray(), [{_id: 0, a: 0}, {_id: 1, a: 0}, {_id: 2, a: 1}]);
+const txnOpts = {
+ writeConcern: {w: "majority"}
+};
-assert.commandWorked(session.commitTransaction_forTesting());
+jsTest.log("Do an empty multi-update.");
+withTxnAndAutoRetryOnMongos(session, () => {
+ // Update 0 docs.
+ let res = assert.commandWorked(sessionColl.update({a: 99}, {$set: {b: 1}}, {multi: true}));
+ assert.eq(0, res.nModified);
+ res = sessionColl.find({});
+ assert.sameMembers(res.toArray(), [{_id: 0, a: 0}, {_id: 1, a: 0}, {_id: 2, a: 1}]);
+}, txnOpts);
jsTest.log("Do a single-result multi-update.");
-session.startTransaction({writeConcern: {w: "majority"}});
-
-// Update 1 doc.
-res = sessionColl.update({a: 1}, {$set: {b: 1}}, {multi: true});
-assert.eq(1, res.nModified);
-res = sessionColl.find({});
-assert.sameMembers(res.toArray(), [{_id: 0, a: 0}, {_id: 1, a: 0}, {_id: 2, a: 1, b: 1}]);
-
-assert.commandWorked(session.commitTransaction_forTesting());
+withTxnAndAutoRetryOnMongos(session, () => {
+ // Update 1 doc.
+ let res = assert.commandWorked(sessionColl.update({a: 1}, {$set: {b: 1}}, {multi: true}));
+ assert.eq(1, res.nModified);
+ res = sessionColl.find({});
+ assert.sameMembers(res.toArray(), [{_id: 0, a: 0}, {_id: 1, a: 0}, {_id: 2, a: 1, b: 1}]);
+}, txnOpts);
jsTest.log("Do a multiple-result multi-update.");
-session.startTransaction({writeConcern: {w: "majority"}});
-
-// Update 2 docs.
-res = sessionColl.update({a: 0}, {$set: {b: 2}}, {multi: true});
-assert.eq(2, res.nModified);
-res = sessionColl.find({});
-assert.sameMembers(res.toArray(),
- [{_id: 0, a: 0, b: 2}, {_id: 1, a: 0, b: 2}, {_id: 2, a: 1, b: 1}]);
-
-assert.commandWorked(session.commitTransaction_forTesting());
+withTxnAndAutoRetryOnMongos(session, () => {
+ // Update 2 docs.
+ let res = assert.commandWorked(sessionColl.update({a: 0}, {$set: {b: 2}}, {multi: true}));
+ assert.eq(2, res.nModified);
+ res = sessionColl.find({});
+ assert.sameMembers(res.toArray(),
+ [{_id: 0, a: 0, b: 2}, {_id: 1, a: 0, b: 2}, {_id: 2, a: 1, b: 1}]);
+}, txnOpts);
jsTest.log("Do a multiple-query multi-update.");
-session.startTransaction({writeConcern: {w: "majority"}});
-
-// Bulk update 3 docs.
-let bulk = sessionColl.initializeUnorderedBulkOp();
-bulk.find({a: 0}).update({$set: {c: 1}});
-bulk.find({_id: 2}).update({$set: {c: 2}});
-res = assert.commandWorked(bulk.execute());
-assert.eq(3, res.nModified);
-
-res = sessionColl.find({});
-assert.sameMembers(
- res.toArray(),
- [{_id: 0, a: 0, b: 2, c: 1}, {_id: 1, a: 0, b: 2, c: 1}, {_id: 2, a: 1, b: 1, c: 2}]);
-
-assert.commandWorked(session.commitTransaction_forTesting());
+withTxnAndAutoRetryOnMongos(session, () => {
+ // Bulk update 3 docs.
+ let bulk = sessionColl.initializeUnorderedBulkOp();
+ bulk.find({a: 0}).update({$set: {c: 1}});
+ bulk.find({_id: 2}).update({$set: {c: 2}});
+ let res = assert.commandWorked(bulk.execute());
+ assert.eq(3, res.nModified);
+
+ res = sessionColl.find({});
+ assert.sameMembers(
+ res.toArray(),
+ [{_id: 0, a: 0, b: 2, c: 1}, {_id: 1, a: 0, b: 2, c: 1}, {_id: 2, a: 1, b: 1, c: 2}]);
+}, txnOpts);
jsTest.log("Do a multi-update with upsert.");
-session.startTransaction({writeConcern: {w: "majority"}});
-
-// Upsert 1 doc.
-res = sessionColl.update({_id: 3}, {$set: {d: 1}}, {multi: true, upsert: true});
-assert.eq(1, res.nUpserted);
-res = sessionColl.find({});
-assert.sameMembers(res.toArray(), [
- {_id: 0, a: 0, b: 2, c: 1},
- {_id: 1, a: 0, b: 2, c: 1},
- {_id: 2, a: 1, b: 1, c: 2},
- {_id: 3, d: 1}
-]);
-
-assert.commandWorked(session.commitTransaction_forTesting());
+withTxnAndAutoRetryOnMongos(session, () => {
+ // Upsert 1 doc.
+ let res = assert.commandWorked(
+ sessionColl.update({_id: 3}, {$set: {d: 1}}, {multi: true, upsert: true}));
+ assert.eq(1, res.nUpserted);
+ res = sessionColl.find({});
+ assert.sameMembers(res.toArray(), [
+ {_id: 0, a: 0, b: 2, c: 1},
+ {_id: 1, a: 0, b: 2, c: 1},
+ {_id: 2, a: 1, b: 1, c: 2},
+ {_id: 3, d: 1}
+ ]);
+}, txnOpts);
}());