diff options
author | William Schultz <william.schultz@mongodb.com> | 2018-05-02 13:23:13 -0400 |
---|---|---|
committer | William Schultz <william.schultz@mongodb.com> | 2018-05-02 13:23:13 -0400 |
commit | e8fe32029aded4d0e909f531196edff43c96cfff (patch) | |
tree | d9f4e02e7ad6fc9e07083908761ae230c9ab4b34 /src/mongo/db/session_test.cpp | |
parent | bbe227d11d937088f832c5e485f16621d4251966 (diff) | |
download | mongo-e8fe32029aded4d0e909f531196edff43c96cfff.tar.gz |
SERVER-34557 Restrict transactions to only run against replica set primaries
Diffstat (limited to 'src/mongo/db/session_test.cpp')
-rw-r--r-- | src/mongo/db/session_test.cpp | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/src/mongo/db/session_test.cpp b/src/mongo/db/session_test.cpp index ab0c4a4e32a..f992721decc 100644 --- a/src/mongo/db/session_test.cpp +++ b/src/mongo/db/session_test.cpp @@ -782,70 +782,6 @@ TEST_F(SessionTest, AutocommitRequiredOnEveryTxnOp) { session.beginOrContinueTxn(opCtx(), txnNum, false, boost::none); } -TEST_F(SessionTest, TransactionsOnlyPermitAllowedReadPreferences) { - const auto sessionId = makeLogicalSessionIdForTest(); - Session session(sessionId); - session.refreshFromStorageIfNeeded(opCtx()); - TxnNumber txnNum = 1; - - // - // Multi-statement transaction operations can only be run with 'readPreference=primary'. - // - - auto startTxnWithReadPref = [&](ReadPreference readPref, - boost::optional<bool> autocommit, - boost::optional<bool> startTransaction) { - txnNum++; - ReadPreferenceSetting::get(opCtx()) = ReadPreferenceSetting(readPref); - session.beginOrContinueTxn(opCtx(), txnNum, autocommit, startTransaction); - }; - - // Shouldn't throw. - startTxnWithReadPref(ReadPreference::PrimaryOnly, false, true); - ASSERT_TRUE(session.inSnapshotReadOrMultiDocumentTransaction()); - - // All unsupported read preferences should throw. - ASSERT_THROWS_CODE(startTxnWithReadPref(ReadPreference::PrimaryPreferred, false, true), - AssertionException, - 50789); - ASSERT_THROWS_CODE(startTxnWithReadPref(ReadPreference::SecondaryOnly, false, true), - AssertionException, - 50789); - ASSERT_THROWS_CODE(startTxnWithReadPref(ReadPreference::SecondaryPreferred, false, true), - AssertionException, - 50789); - ASSERT_THROWS_CODE( - startTxnWithReadPref(ReadPreference::Nearest, false, true), AssertionException, 50789); - - // - // Operations that are not on a multi-statement transaction are allowed to specify any - // readPreference. - // - - auto activeTxnNum = TxnNumber{-1}; - - // None of these should throw. Each should start a transaction with a new, higher, transaction - // number. - startTxnWithReadPref(ReadPreference::PrimaryOnly, boost::none, boost::none); - ASSERT_GT(session.getActiveTxnNumberForTest(), activeTxnNum); - activeTxnNum = session.getActiveTxnNumberForTest(); - - startTxnWithReadPref(ReadPreference::PrimaryPreferred, boost::none, boost::none); - ASSERT_GT(session.getActiveTxnNumberForTest(), activeTxnNum); - activeTxnNum = session.getActiveTxnNumberForTest(); - - startTxnWithReadPref(ReadPreference::SecondaryOnly, boost::none, boost::none); - ASSERT_GT(session.getActiveTxnNumberForTest(), activeTxnNum); - activeTxnNum = session.getActiveTxnNumberForTest(); - - startTxnWithReadPref(ReadPreference::SecondaryPreferred, boost::none, boost::none); - ASSERT_GT(session.getActiveTxnNumberForTest(), activeTxnNum); - activeTxnNum = session.getActiveTxnNumberForTest(); - - startTxnWithReadPref(ReadPreference::Nearest, boost::none, boost::none); - ASSERT_GT(session.getActiveTxnNumberForTest(), activeTxnNum); -} - TEST_F(SessionTest, SameTransactionPreservesStoredStatements) { Session::registerCursorKillFunction(noopKillCursorFunction); Session::registerCursorExistsFunction(noopCursorExistsFunction); |