summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2022-04-15 01:24:42 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-04-15 01:50:45 +0000
commitad3b2e8eca1595d94fb096c4348f61b320ea4716 (patch)
tree7089745f2870e9a260bf6992ae601b9869fc3213
parent4221d7b10b1dee601e7cc116d3ba70c2d6fda20c (diff)
downloadmongo-ad3b2e8eca1595d94fb096c4348f61b320ea4716.tar.gz
SERVER-65545 Delegate `ClockSourceMock` to `ServiceContextMongoDTest`
(cherry picked from commit 576ea084ea887f3f6bd1dd1f8aa12c1af33487d1)
-rw-r--r--src/mongo/db/s/transaction_coordinator_test.cpp4
-rw-r--r--src/mongo/db/storage/kv/kv_engine_test_harness.cpp2
-rw-r--r--src/mongo/db/transaction_participant_test.cpp16
3 files changed, 5 insertions, 17 deletions
diff --git a/src/mongo/db/s/transaction_coordinator_test.cpp b/src/mongo/db/s/transaction_coordinator_test.cpp
index 10fc7892fb3..75884bb136f 100644
--- a/src/mongo/db/s/transaction_coordinator_test.cpp
+++ b/src/mongo/db/s/transaction_coordinator_test.cpp
@@ -1316,10 +1316,10 @@ TEST_F(TransactionCoordinatorTest,
class TransactionCoordinatorMetricsTest : public TransactionCoordinatorTestBase {
protected:
TransactionCoordinatorMetricsTest()
- : TransactionCoordinatorTestBase(Options{}.useMockTickSource<Microseconds>(true)) {}
+ : TransactionCoordinatorTestBase(
+ Options{}.useMockClock(true).useMockTickSource<Microseconds>(true)) {}
void setUp() override {
- getServiceContext()->setPreciseClockSource(std::make_unique<ClockSourceMock>());
tickSource()->reset(1);
TransactionCoordinatorTestBase::setUp();
diff --git a/src/mongo/db/storage/kv/kv_engine_test_harness.cpp b/src/mongo/db/storage/kv/kv_engine_test_harness.cpp
index 00f128bf12e..de86431f25c 100644
--- a/src/mongo/db/storage/kv/kv_engine_test_harness.cpp
+++ b/src/mongo/db/storage/kv/kv_engine_test_harness.cpp
@@ -150,8 +150,6 @@ protected:
}
};
-const std::unique_ptr<ClockSource> clock = std::make_unique<ClockSourceMock>();
-
TEST_F(KVEngineTestHarness, SimpleRS1) {
std::unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create(getServiceContext()));
KVEngine* engine = helper->getEngine();
diff --git a/src/mongo/db/transaction_participant_test.cpp b/src/mongo/db/transaction_participant_test.cpp
index e0acd2b9f45..c42faa91cf4 100644
--- a/src/mongo/db/transaction_participant_test.cpp
+++ b/src/mongo/db/transaction_participant_test.cpp
@@ -1826,7 +1826,7 @@ TEST_F(TxnParticipantTest, ReacquireLocksForPreparedTransactionsOnStepUp) {
class TransactionsMetricsTest : public TxnParticipantTest {
protected:
TransactionsMetricsTest()
- : TxnParticipantTest(Options{}.useMockTickSource<Microseconds>(true)) {}
+ : TxnParticipantTest(Options{}.useMockClock(true).useMockTickSource<Microseconds>(true)) {}
void setUp() override {
TxnParticipantTest::setUp();
@@ -1836,14 +1836,6 @@ protected:
}
/**
- * Set up and return a mock clock source.
- */
- ClockSourceMock* initMockPreciseClockSource() {
- getServiceContext()->setPreciseClockSource(std::make_unique<ClockSourceMock>());
- return dynamic_cast<ClockSourceMock*>(getServiceContext()->getPreciseClockSource());
- }
-
- /**
* Returns the mock tick source.
*/
TickSourceMock<Microseconds>* mockTickSource() {
@@ -2879,9 +2871,8 @@ TEST_F(TransactionsMetricsTest, TimeInactiveMicrosShouldIncreaseUntilCommit) {
TEST_F(TransactionsMetricsTest, ReportStashedResources) {
auto tickSource = mockTickSource();
- auto clockSource = initMockPreciseClockSource();
auto startTime = Date_t::now();
- clockSource->reset(startTime);
+ ClockSourceMock{}.reset(startTime);
const bool autocommit = false;
@@ -2981,9 +2972,8 @@ TEST_F(TransactionsMetricsTest, ReportStashedResources) {
TEST_F(TransactionsMetricsTest, ReportUnstashedResources) {
auto tickSource = mockTickSource();
- auto clockSource = initMockPreciseClockSource();
auto startTime = Date_t::now();
- clockSource->reset(startTime);
+ ClockSourceMock{}.reset(startTime);
ASSERT(opCtx()->lockState());
ASSERT(opCtx()->recoveryUnit());