summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorPavi Vetriselvan <pvselvan@umich.edu>2018-08-02 10:41:07 -0400
committerPavi Vetriselvan <pvselvan@umich.edu>2018-08-02 11:06:36 -0400
commitafaf46687eb3930ddbfc8b528bd68295b6a09676 (patch)
treee1d7142b8c0736d3393ff22baba1ed395e6283e1 /jstests
parent308fc1b550fd7343e9168b8d87e5a4065cd4afda (diff)
downloadmongo-afaf46687eb3930ddbfc8b528bd68295b6a09676.tar.gz
SERVER-35808 Returns error when new txns start on a session with existing prepared txn
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/txns/no_new_transactions_when_prepared_transaction_in_progress.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/jstests/core/txns/no_new_transactions_when_prepared_transaction_in_progress.js b/jstests/core/txns/no_new_transactions_when_prepared_transaction_in_progress.js
new file mode 100644
index 00000000000..711135b5c46
--- /dev/null
+++ b/jstests/core/txns/no_new_transactions_when_prepared_transaction_in_progress.js
@@ -0,0 +1,57 @@
+/**
+ * Tests that we cannot start a new transaction when a prepared transaction exists on the session.
+ * @tags: [uses_transactions]
+ *
+ */
+
+(function() {
+ "use strict";
+ load("jstests/core/txns/libs/prepare_helpers.js");
+
+ const dbName = "test";
+ const collName = "no_new_transactions_when_prepared_transaction_in_progress";
+ const testDB = db.getSiblingDB(dbName);
+
+ testDB.runCommand({drop: collName, writeConcern: {w: "majority"}});
+
+ assert.commandWorked(testDB.runCommand({create: collName, writeConcern: {w: "majority"}}));
+
+ const sessionOptions = {causalConsistency: false};
+ const session = testDB.getMongo().startSession(sessionOptions);
+ const sessionDb = session.getDatabase(dbName);
+ const sessionColl = sessionDb.getCollection(collName);
+
+ jsTestLog(
+ "Test starting a new transaction while an existing prepared transaction exists on the " +
+ "session.");
+ session.startTransaction();
+ assert.commandWorked(sessionColl.insert({_id: "insert-1"}));
+ PrepareHelpers.prepareTransaction(session);
+ assert.commandFailedWithCode(sessionDb.runCommand({
+ insert: collName,
+ documents: [{_id: "cannot_start"}],
+ readConcern: {level: "snapshot"},
+ txnNumber: NumberLong(1),
+ stmtId: NumberInt(0),
+ startTransaction: true,
+ autocommit: false
+ }),
+ ErrorCodes.PreparedTransactionInProgress);
+
+ jsTestLog(
+ "Test error precedence when executing a malformed command during a prepared transaction.");
+ // The following command specifies txnNumber: 2 without startTransaction: true.
+ assert.commandFailedWithCode(sessionDb.runCommand({
+ insert: collName,
+ documents: [{_id: "no_such_txn"}],
+ readConcern: {level: "snapshot"},
+ txnNumber: NumberLong(2),
+ stmtId: NumberInt(0),
+ autocommit: false
+ }),
+ ErrorCodes.NoSuchTransaction);
+
+ session.abortTransaction();
+
+ session.endSession();
+}()); \ No newline at end of file