diff options
| author | Jason Chan <jason.chan@mongodb.com> | 2020-02-25 19:37:37 +0000 |
|---|---|---|
| committer | evergreen <evergreen@mongodb.com> | 2020-02-25 19:37:37 +0000 |
| commit | ad4fc77306b08a76cf3ec19e249e811b566dd464 (patch) | |
| tree | e0dc2cb81125ad231c27b9e7689b60c9d24486af /jstests | |
| parent | 6a5e4ec3084a1067f25d3aa904e1dac2c2abc90e (diff) | |
| download | mongo-ad4fc77306b08a76cf3ec19e249e811b566dd464.tar.gz | |
SERVER-46238 Transaction will abort properly when expiring in the middle of commitTransaction
Diffstat (limited to 'jstests')
| -rw-r--r-- | jstests/replsets/txn_expires_during_commit.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/jstests/replsets/txn_expires_during_commit.js b/jstests/replsets/txn_expires_during_commit.js new file mode 100644 index 00000000000..43a396466cf --- /dev/null +++ b/jstests/replsets/txn_expires_during_commit.js @@ -0,0 +1,42 @@ +/** + * Tests that a transaction will be aborted properly if it expires in the middle of a + * commitTransaction. + * + * @tags: [uses_transactions] + */ + +(function() { + "use strict"; + + const replTest = new ReplSetTest({nodes: 1}); + replTest.startSet(); + replTest.initiate(); + + const primary = replTest.getPrimary(); + assert.commandWorked( + primary.adminCommand({setParameter: 1, transactionLifetimeLimitSeconds: 5})); + + const session = primary.getDB("test").getMongo().startSession(); + const sessionDb = session.getDatabase("test"); + assert.commandWorked(sessionDb.createCollection("c")); + + // Hang in the middle of the commitTransaction command, before the transaction is committed on + // the session. + assert.commandWorked(sessionDb.adminCommand({ + configureFailPoint: "sleepBeforeCommitTransaction", + mode: "alwaysOn", + data: {sleepMillis: NumberInt(999999)} + })); + session.startTransaction(); + assert.commandWorked(sessionDb.c.insert({a: 1})); + // We expect the commitTransction operation to be killed and that the transaction is aborted + // cleanly. + assert.commandFailedWithCode( + sessionDb.adminCommand({commitTransaction: 1, writeConcern: {w: "majority"}}), + ErrorCodes.ExceededTimeLimit); + + // Update the transaction state in the shell. + assert.commandFailedWithCode(session.commitTransaction_forTesting(), + ErrorCodes.NoSuchTransaction); + replTest.stopSet(); +})(); |
