diff options
author | Gregory Noma <gregory.noma@gmail.com> | 2022-11-08 19:24:14 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-11-08 20:35:53 +0000 |
commit | 35c314ab1a215dc79fcec0a0874803086e220f88 (patch) | |
tree | fcdc365489306d8d336841c5728f6aac67046867 | |
parent | cf648f7bc75f11fa316f6e9fbb737cf9763742c3 (diff) | |
download | mongo-35c314ab1a215dc79fcec0a0874803086e220f88.tar.gz |
SERVER-71167 Abort transactions in `txn_index_catalog_changes.js`
-rw-r--r-- | jstests/noPassthrough/txn_index_catalog_changes.js | 42 |
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(); |