summaryrefslogtreecommitdiff
path: root/jstests/replsets/shutdown_with_prepared_transaction.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/replsets/shutdown_with_prepared_transaction.js')
-rw-r--r--jstests/replsets/shutdown_with_prepared_transaction.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/jstests/replsets/shutdown_with_prepared_transaction.js b/jstests/replsets/shutdown_with_prepared_transaction.js
new file mode 100644
index 00000000000..387d7474ef3
--- /dev/null
+++ b/jstests/replsets/shutdown_with_prepared_transaction.js
@@ -0,0 +1,38 @@
+/**
+ * Tests that a server can still be shut down while it has prepared transactions pending.
+ *
+ * @tags: [uses_transactions]
+ */
+(function() {
+ "use strict";
+ load("jstests/core/txns/libs/prepare_helpers.js");
+
+ const replTest = new ReplSetTest({nodes: 1});
+ replTest.startSet();
+ replTest.initiate();
+
+ const conn = replTest.getPrimary();
+
+ const dbName = "test";
+ const collName = "shutdown_with_prepared_txn";
+ const testDB = conn.getDB(dbName);
+ const testColl = testDB.getCollection(collName);
+
+ assert.commandWorked(testDB.runCommand({create: collName, writeConcern: {w: "majority"}}));
+
+ const session = conn.startSession({causalConsistency: false});
+ const sessionDB = session.getDatabase(dbName);
+ const sessionColl = sessionDB.getCollection(collName);
+
+ jsTestLog("Starting a simple transaction and putting it into prepare");
+
+ session.startTransaction();
+ assert.commandWorked(sessionColl.insert({_id: 1}));
+
+ PrepareHelpers.prepareTransaction(session);
+
+ jsTestLog("Shutting down the set with the transaction still in prepare state");
+ // Skip validation during ReplSetTest cleanup since validate() will block behind the prepared
+ // transaction's locks when trying to take a collection X lock.
+ replTest.stopSet(null /*signal*/, false /*forRestart*/, {skipValidation: true});
+}());