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:47:48 +0000
commit53df6dcf7350177ab3b982492c7334f741fb3ba0 (patch)
treea318f49b150292d1f8a2f3d6c19aac1b5651b084
parent7b4d0c59a2c057e71d465d6fd24e80693a538538 (diff)
downloadmongo-53df6dcf7350177ab3b982492c7334f741fb3ba0.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();