summaryrefslogtreecommitdiff
path: root/jstests/replsets/shutdown_with_prepared_transaction.js
blob: d241df1a68b467dd9ae7e3f45a6869bcb2811f77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
 * Tests that a server can still be shut down while it has prepared transactions pending.
 *
 * @tags: [uses_transactions, uses_prepare_transaction]
 */
(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});
}());