summaryrefslogtreecommitdiff
path: root/src/mongo/s/transaction_router_test.cpp
diff options
context:
space:
mode:
authorJack Mulrow <jack.mulrow@mongodb.com>2018-10-04 00:45:16 -0400
committerJack Mulrow <jack.mulrow@mongodb.com>2018-10-09 09:39:08 -0400
commitf2254e26b9c7bdd94e4e6613ef5a20302ecc855e (patch)
tree9f6a456281d21f15d9eeb67f0a37650826d510e0 /src/mongo/s/transaction_router_test.cpp
parentd2d7dbadcc008a484218321666aae44b75964787 (diff)
downloadmongo-f2254e26b9c7bdd94e4e6613ef5a20302ecc855e.tar.gz
SERVER-37223 Place readConcernArgs on opCtx for subsequent statements in sharded transactions
Diffstat (limited to 'src/mongo/s/transaction_router_test.cpp')
-rw-r--r--src/mongo/s/transaction_router_test.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/mongo/s/transaction_router_test.cpp b/src/mongo/s/transaction_router_test.cpp
index b0da4b30af0..cb211627533 100644
--- a/src/mongo/s/transaction_router_test.cpp
+++ b/src/mongo/s/transaction_router_test.cpp
@@ -30,6 +30,7 @@
#include "mongo/client/remote_command_targeter_mock.h"
#include "mongo/db/logical_clock.h"
+#include "mongo/db/repl/read_concern_args.h"
#include "mongo/s/sharding_router_test_fixture.h"
#include "mongo/s/transaction_router.h"
#include "mongo/unittest/death_test.h"
@@ -1366,5 +1367,46 @@ TEST_F(TransactionRouterTest, ImplicitAbortIgnoresErrors) {
future.timed_get(kFutureTimeout);
}
+TEST_F(TransactionRouterTest, ContinuingTransactionPlacesItsReadConcernOnOpCtx) {
+ TxnNumber txnNum{3};
+
+ TransactionRouter txnRouter({});
+ txnRouter.checkOut();
+ txnRouter.beginOrContinueTxn(operationContext(), txnNum, true);
+ txnRouter.setAtClusterTimeToLatestTime(operationContext());
+
+ repl::ReadConcernArgs::get(operationContext()) = repl::ReadConcernArgs();
+ txnRouter.beginOrContinueTxn(operationContext(), txnNum, false);
+
+ ASSERT(repl::ReadConcernArgs::get(operationContext()).getLevel() ==
+ repl::ReadConcernLevel::kSnapshotReadConcern);
+}
+
+TEST_F(TransactionRouterTest, SubsequentStatementCanSelectAtClusterTimeIfNotSelectedYet) {
+ TxnNumber txnNum{3};
+
+ TransactionRouter txnRouter({});
+ txnRouter.checkOut();
+ txnRouter.beginOrContinueTxn(operationContext(), txnNum, true);
+
+ // First statement does not select an atClusterTime, but does not target any participants.
+
+ repl::ReadConcernArgs::get(operationContext()) = repl::ReadConcernArgs();
+ txnRouter.beginOrContinueTxn(operationContext(), txnNum, false);
+
+ // Subsequent statement does select an atClusterTime and does target a participant.
+ txnRouter.setAtClusterTimeToLatestTime(operationContext());
+
+ BSONObj expectedReadConcern = BSON("level"
+ << "snapshot"
+ << "atClusterTime"
+ << kInMemoryLogicalTime.asTimestamp());
+
+ auto newCmd = txnRouter.attachTxnFieldsIfNeeded(shard1,
+ BSON("insert"
+ << "test"));
+ ASSERT_BSONOBJ_EQ(expectedReadConcern, newCmd["readConcern"].Obj());
+}
+
} // unnamed namespace
} // namespace mongo