summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTess Avitabile <tess.avitabile@mongodb.com>2020-05-21 14:26:24 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-05-26 15:26:51 +0000
commitba7d21608131d8236f2c2b66a93c9d6311f8506c (patch)
tree7445bd3087a067eabf2f8539101e4a66179ada7b
parente57f88e54188edc673a434a2623374c12c7e77f4 (diff)
downloadmongo-ba7d21608131d8236f2c2b66a93c9d6311f8506c.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.js40
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 eb6aa6dad6e..b72e65b00d9 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.writeOK(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();
})();