diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2020-05-21 14:26:24 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-05-26 16:04:39 +0000 |
commit | 29f8ca9ec2fef177f98928ee4c1ec6168db5cf87 (patch) | |
tree | caeb459e408bac4deec7a93672018fcec0cf4ef0 | |
parent | b54c9c8f37783b8d8906988cd8c5f7625582f5cb (diff) | |
download | mongo-29f8ca9ec2fef177f98928ee4c1ec6168db5cf87.tar.gz |
SERVER-48371 transactions_during_step_down.js must abort transaction in the shell
(cherry picked from commit ec3fe1a2b7cbf6586b20373fdca1e60dd9e406d4)
-rw-r--r-- | jstests/replsets/transactions_during_step_down.js | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/jstests/replsets/transactions_during_step_down.js b/jstests/replsets/transactions_during_step_down.js index c74062cb5e5..6e73475ad73 100644 --- a/jstests/replsets/transactions_during_step_down.js +++ b/jstests/replsets/transactions_during_step_down.js @@ -31,20 +31,17 @@ TestData.dbName = dbName; TestData.collName = collName; TestData.skipRetryOnNetworkError = true; -function startTxn({parallel: parallel = true}) { - var txnFunc = () => { - jsTestLog("Starting a new transaction."); - const session = db.getMongo().startSession(); - const sessionDb = session.getDatabase(TestData.dbName); - const sessionColl = sessionDb[TestData.collName]; - session.startTransaction({writeConcern: {w: "majority"}}); - print(TestData.cmd); - eval(TestData.cmd); - - // Validate that the connection is not closed on step down. - assert.commandWorked(db.adminCommand({ping: 1})); - }; - return parallel ? startParallelShell(txnFunc, primary.port) : txnFunc(); +function txnFunc() { + jsTestLog("Starting a new transaction."); + const session = db.getMongo().startSession(); + const sessionDb = session.getDatabase(TestData.dbName); + const sessionColl = sessionDb[TestData.collName]; + session.startTransaction({writeConcern: {w: "majority"}}); + print(TestData.cmd); + eval(TestData.cmd); + + // Validate that the connection is not closed on step down. + assert.commandWorked(db.adminCommand({ping: 1})); } function runStepDown() { @@ -78,7 +75,7 @@ function testTxnFailsWithCode({ // Start transaction. TestData.cmd = preOp + `assert.commandFailedWithCode(${op}, ErrorCodes.InterruptedDueToReplStateChange);`; - const waitForTxnShell = startTxn({}); + const waitForTxnShell = startParallelShell(txnFunc, primary.port); jsTestLog("Waiting for primary to reach failPoint '" + failPoint + "'."); waitForCurOpByFailPoint(primaryAdmin, nss, failPoint); @@ -120,15 +117,22 @@ testAbortOrCommitTxnFailsWithCode( {failPoint: "hangBeforeAbortingTxn", op: "session.abortTransaction_forTesting()"}); jsTestLog("Testing stepdown during running transaction in inactive state."); -TestData.cmd = "assert.commandWorked(sessionColl.insert({_id: 'inactiveTxnOp'}))"; // Do not start the transaction in parallel shell because when the parallel // shell work is done, implicit call to "endSessions" and "abortTransaction" // cmds are made. So, during step down we might not have any running -// transaction to interrupt. -startTxn({parallel: false}); +jsTestLog("Starting a new transaction."); +const session = db.getMongo().startSession(); +const sessionDb = session.getDatabase(TestData.dbName); +const sessionColl = sessionDb[TestData.collName]; +session.startTransaction({writeConcern: {w: "majority"}}); +assert.commandWorked(sessionColl.insert({_id: 'inactiveTxnOp'})); // Call step down & validate data. runStepDown(); +// Even though the transaction was aborted by the stepdown, we must still update the shell's +// transaction state to aborted. +assert.commandFailedWithCode(session.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction); + rst.stopSet(); })(); |