diff options
author | Spencer T Brody <spencer@mongodb.com> | 2018-09-12 14:24:53 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2018-09-13 14:47:18 -0400 |
commit | e54a379fa19a91bd5e59752fc705d9a98e5ba453 (patch) | |
tree | 77d0ef5a88d6a92fd0b2af4e42b82273bc226f3b /jstests | |
parent | 7c13a75b928ace3f65c9553352689dc0a6d0ca83 (diff) | |
download | mongo-e54a379fa19a91bd5e59752fc705d9a98e5ba453.tar.gz |
SERVER-35817 Allow shutdowns while prepared transactions are in-flight
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/replsets/shutdown_with_prepared_transaction.js | 38 |
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}); +}()); |