diff options
author | Samy Lanka <samy.lanka@gmail.com> | 2018-07-31 16:36:09 -0400 |
---|---|---|
committer | Samy Lanka <samy.lanka@gmail.com> | 2018-08-01 16:19:57 -0400 |
commit | 124b9963e852ca8cb845c893922b63e26eaed3a5 (patch) | |
tree | 23fb0d7c8ad2c7ff359a5feb6a2a561557ce0986 /jstests | |
parent | 30298ed63aadae19bd5494dd0e1f33e329389806 (diff) | |
download | mongo-124b9963e852ca8cb845c893922b63e26eaed3a5.tar.gz |
SERVER-35864 Ensure the active transaction on the session has not already been commit or aborted when receiving a prepareTransaction command
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/core/txns/prepare_committed_transaction.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/jstests/core/txns/prepare_committed_transaction.js b/jstests/core/txns/prepare_committed_transaction.js new file mode 100644 index 00000000000..6e9eb35ba5c --- /dev/null +++ b/jstests/core/txns/prepare_committed_transaction.js @@ -0,0 +1,54 @@ +/** + * Test error cases when calling prepare on a committed transaction. + * + * @tags: [uses_transactions] + */ +(function() { + "use strict"; + + const dbName = "test"; + const collName = "prepare_committed_transaction"; + const testDB = db.getSiblingDB(dbName); + const testColl = testDB.getCollection(collName); + + testColl.drop({writeConcern: {w: "majority"}}); + assert.commandWorked(testDB.runCommand({create: collName, writeConcern: {w: "majority"}})); + + const session = db.getMongo().startSession({causalConsistency: false}); + const sessionDB = session.getDatabase(dbName); + const sessionColl = sessionDB.getCollection(collName); + + const doc = {x: 1}; + + jsTestLog("Test that calling prepare on a committed transaction fails."); + session.startTransaction(); + assert.commandWorked(sessionColl.insert(doc)); + session.commitTransaction(); + assert.commandFailedWithCode( + sessionDB.adminCommand( + {prepareTransaction: 1, txnNumber: NumberLong(0), autocommit: false}), + ErrorCodes.TransactionCommitted); + + jsTestLog("Test the error precedence when calling prepare on a committed transaction but not " + + "providing txnNumber to prepareTransaction."); + assert.commandFailedWithCode(sessionDB.adminCommand({prepareTransaction: 1, autocommit: false}), + ErrorCodes.InvalidOptions); + + jsTestLog("Test the error precedence when calling prepare on a committed transaction but not " + + "providing autocommit to prepareTransaction."); + assert.commandFailedWithCode( + sessionDB.adminCommand({prepareTransaction: 1, txnNumber: NumberLong(0)}), + ErrorCodes.InvalidOptions); + + jsTestLog("Test the error precedence when calling prepare on a committed transaction and " + + "providing startTransaction to prepareTransaction."); + assert.commandFailedWithCode(sessionDB.adminCommand({ + prepareTransaction: 1, + txnNumber: NumberLong(0), + autocommit: false, + startTransaction: true + }), + ErrorCodes.ConflictingOperationInProgress); + + session.endSession(); +}()); |