summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2022-11-08 19:24:14 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-11-15 22:42:37 +0000
commit340a08e400b8c72d0818986b01a316fd19a1b66e (patch)
treee93d90337810ba9c57fdec43d0e5ba5cfcd12c44
parent8e22d0a400e73070f752ce74bd60f99ec2997746 (diff)
downloadmongo-340a08e400b8c72d0818986b01a316fd19a1b66e.tar.gz
SERVER-71167 Abort transactions in `txn_index_catalog_changes.js`
(cherry picked from commit 35c314ab1a215dc79fcec0a0874803086e220f88)
-rw-r--r--jstests/noPassthrough/txn_index_catalog_changes.js42
1 files changed, 18 insertions, 24 deletions
diff --git a/jstests/noPassthrough/txn_index_catalog_changes.js b/jstests/noPassthrough/txn_index_catalog_changes.js
index b29a8129a8b..124a4e89c60 100644
--- a/jstests/noPassthrough/txn_index_catalog_changes.js
+++ b/jstests/noPassthrough/txn_index_catalog_changes.js
@@ -31,18 +31,15 @@ const db = primary.getDB('test');
// Start a transaction whose snapshot predates the completion of the index build, and which
// reserves an oplog entry after the index build commits.
- try {
- const s1 = db.getMongo().startSession();
- s1.startTransaction({readConcern: {level: "snapshot", atClusterTime: clusterTime}});
- s1.getDatabase('test').c.insertOne({_id: 1, num: 1});
-
- // Transaction should have failed.
- assert(0);
- } catch (e) {
- assert(e.hasOwnProperty("errorLabels"), tojson(e));
- assert.contains("TransientTransactionError", e.errorLabels, tojson(e));
- assert.eq(e["code"], ErrorCodes.WriteConflict, tojson(e));
- }
+ const s1 = db.getMongo().startSession();
+ s1.startTransaction({readConcern: {level: "snapshot", atClusterTime: clusterTime}});
+
+ const res = assert.commandFailedWithCode(s1.getDatabase('test').c.insert({_id: 1, num: 1}),
+ ErrorCodes.WriteConflict);
+ assert(res.hasOwnProperty("errorLabels"), tojson(res));
+ assert.contains("TransientTransactionError", res.errorLabels, tojson(res));
+
+ assert.commandFailedWithCode(s1.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction);
}
db.c.drop();
@@ -62,18 +59,15 @@ db.c.drop();
// Start a transaction whose snapshot predates the completion of the index build, and which
// reserves an oplog entry after the index build commits.
- try {
- const s1 = db.getMongo().startSession();
- s1.startTransaction({readConcern: {level: "snapshot", atClusterTime: clusterTime}});
- s1.getDatabase('test').c.deleteOne({_id: 0});
-
- // Transaction should have failed.
- assert(0);
- } catch (e) {
- assert(e.hasOwnProperty("errorLabels"), tojson(e));
- assert.contains("TransientTransactionError", e.errorLabels, tojson(e));
- assert.eq(e["code"], ErrorCodes.WriteConflict, tojson(e));
- }
+ const s1 = db.getMongo().startSession();
+ s1.startTransaction({readConcern: {level: "snapshot", atClusterTime: clusterTime}});
+
+ const res = assert.commandFailedWithCode(s1.getDatabase('test').c.remove({_id: 0}),
+ ErrorCodes.WriteConflict);
+ assert(res.hasOwnProperty("errorLabels"), tojson(res));
+ assert.contains("TransientTransactionError", res.errorLabels, tojson(res));
+
+ assert.commandFailedWithCode(s1.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction);
}
replTest.stopSet();