diff options
Diffstat (limited to 'src/mongo/db/repl/primary_only_service_test.cpp')
| -rw-r--r-- | src/mongo/db/repl/primary_only_service_test.cpp | 111 |
1 files changed, 42 insertions, 69 deletions
diff --git a/src/mongo/db/repl/primary_only_service_test.cpp b/src/mongo/db/repl/primary_only_service_test.cpp index ae8d85390ee..90e420bdafb 100644 --- a/src/mongo/db/repl/primary_only_service_test.cpp +++ b/src/mongo/db/repl/primary_only_service_test.cpp @@ -520,21 +520,16 @@ TEST_F(PrimaryOnlyServiceTest, LookupInstance) { ASSERT(instance.get()); ASSERT_EQ(0, instance->getID()); - auto [instance2, isPausedOrShutdown2] = - TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); - ASSERT_TRUE(instance2); - ASSERT_FALSE(isPausedOrShutdown2); + auto instance2 = TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)).get(); - ASSERT_EQ(instance.get(), instance2.value().get()); + ASSERT_EQ(instance.get(), instance2.get()); TestServiceHangDuringInitialization.setMode(FailPoint::off); instance->getCompletionFuture().get(); // Shouldn't be able to look up instance after it has completed running. - auto [instance3, isPausedOrShutdown3] = - TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); - ASSERT_FALSE(instance3); - ASSERT_FALSE(isPausedOrShutdown3); + auto instance3 = TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); + ASSERT_FALSE(instance3.is_initialized()); } TEST_F(PrimaryOnlyServiceTest, LookupInstanceInterruptible) { @@ -569,11 +564,9 @@ TEST_F(PrimaryOnlyServiceTest, LookupInstanceHoldingISLock) { opCtx->setAlwaysInterruptAtStepDownOrUp(); ASSERT_FALSE(opCtx->lockState()->wasGlobalLockTakenInModeConflictingWithWrites()); - auto [instance2, isPausedOrShutdown] = - TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); - ASSERT_TRUE(instance2); - ASSERT_FALSE(isPausedOrShutdown); - ASSERT_EQ(instance.get(), instance2.value().get()); + auto instance2 = + TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)).get(); + ASSERT_EQ(instance.get(), instance2.get()); } TestServiceHangDuringInitialization.setMode(FailPoint::off); @@ -593,11 +586,9 @@ TEST_F(PrimaryOnlyServiceTest, LookupInstanceHoldingIXLock) { { Lock::GlobalLock lk(opCtx.get(), MODE_IX); ASSERT_FALSE(opCtx->shouldAlwaysInterruptAtStepDownOrUp()); - auto [instance2, isPausedOrShutdown] = - TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); - ASSERT_TRUE(instance2); - ASSERT_FALSE(isPausedOrShutdown); - ASSERT_EQ(instance.get(), instance2.value().get()); + auto instance2 = + TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)).get(); + ASSERT_EQ(instance.get(), instance2.get()); } TestServiceHangDuringInitialization.setMode(FailPoint::off); @@ -640,11 +631,9 @@ TEST_F(PrimaryOnlyServiceTest, LookupInstanceAfterStepDownReturnsNone) { stepDown(); - auto [instance2, isPausedOrShutdown] = - TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); + auto instance2 = TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); - ASSERT_FALSE(instance2); - ASSERT_TRUE(isPausedOrShutdown); + ASSERT_EQ(instance2, boost::none); TestServiceHangDuringInitialization.setMode(FailPoint::off); ASSERT_EQ(ErrorCodes::Interrupted, instance->getCompletionFuture().getNoThrow()); @@ -665,11 +654,9 @@ TEST_F(PrimaryOnlyServiceTest, LookupInstanceAfterShutDownReturnsNone) { shutdown(); - auto [instance2, isPausedOrShutdown] = - TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); + auto instance2 = TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); - ASSERT_FALSE(instance2); - ASSERT_TRUE(isPausedOrShutdown); + ASSERT_EQ(instance2, boost::none); ASSERT_EQ(ErrorCodes::Interrupted, instance->getCompletionFuture().getNoThrow()); } @@ -851,10 +838,8 @@ TEST_F(PrimaryOnlyServiceTest, StepDownBeforePersisted) { auto opCtx = makeOperationContext(); // Since the Instance never wrote its state document, it shouldn't be recreated on stepUp. - auto [recreatedInstance, isPausedOrShutdown] = - TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); - ASSERT_FALSE(recreatedInstance); - ASSERT_FALSE(isPausedOrShutdown); + auto recreatedInstance = TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); + ASSERT(!recreatedInstance.is_initialized()); } TEST_F(PrimaryOnlyServiceTest, RecreateInstanceOnStepUp) { @@ -880,13 +865,11 @@ TEST_F(PrimaryOnlyServiceTest, RecreateInstanceOnStepUp) { { auto opCtx = makeOperationContext(); - auto [recreatedInstance, isPausedOrShutdown] = - TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); - ASSERT_TRUE(recreatedInstance); - ASSERT_FALSE(isPausedOrShutdown); - ASSERT_EQ(TestService::State::kOne, (*recreatedInstance)->getInitialState()); + auto recreatedInstance = + TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)).get(); + ASSERT_EQ(TestService::State::kOne, recreatedInstance->getInitialState()); TestServiceHangDuringStateTwo.waitForTimesEntered(++stateTwoFPTimesEntered); - ASSERT_EQ(TestService::State::kTwo, (*recreatedInstance)->getState()); + ASSERT_EQ(TestService::State::kTwo, recreatedInstance->getState()); } stepDown(); @@ -900,19 +883,17 @@ TEST_F(PrimaryOnlyServiceTest, RecreateInstanceOnStepUp) { { auto opCtx = makeOperationContext(); - auto [recreatedInstance, isPausedOrShutdown1] = - TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); - ASSERT_TRUE(recreatedInstance); - ASSERT_FALSE(isPausedOrShutdown1); - ASSERT_EQ(TestService::State::kTwo, (*recreatedInstance)->getInitialState()); + auto recreatedInstance = + TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)).get(); + ASSERT_EQ(TestService::State::kTwo, recreatedInstance->getInitialState()); TestServiceHangDuringStateOne.setMode(FailPoint::off); - (*recreatedInstance)->getCompletionFuture().get(); - ASSERT_EQ(TestService::State::kDone, (*recreatedInstance)->getState()); + recreatedInstance->getCompletionFuture().get(); + ASSERT_EQ(TestService::State::kDone, recreatedInstance->getState()); + - auto [nonExistentInstance, isPausedOrShutdown2] = + auto nonExistentInstance = TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); - ASSERT_FALSE(nonExistentInstance); - ASSERT_FALSE(isPausedOrShutdown2); + ASSERT(!nonExistentInstance.is_initialized()); } stepDown(); @@ -922,10 +903,9 @@ TEST_F(PrimaryOnlyServiceTest, RecreateInstanceOnStepUp) { auto opCtx = makeOperationContext(); // No Instance should be recreated since the previous run completed successfully and deleted // its state document. - auto [nonExistentInstance, isPausedOrShutdown] = + auto nonExistentInstance = TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); - ASSERT_FALSE(nonExistentInstance); - ASSERT_FALSE(isPausedOrShutdown); + ASSERT(!nonExistentInstance.is_initialized()); } } @@ -981,16 +961,13 @@ TEST_F(PrimaryOnlyServiceTest, StepDownBeforeRebuildingInstances) { TestServiceHangDuringStateOne.waitForTimesEntered(++stateOneFPTimesEntered); auto opCtx = makeOperationContext(); - auto [instance, isPausedOrShutdown] = - TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); - ASSERT_TRUE(instance); - ASSERT_FALSE(isPausedOrShutdown); - ASSERT_EQ(TestService::State::kOne, (*instance)->getInitialState()); - ASSERT_EQ(TestService::State::kOne, (*instance)->getState()); + auto instance = TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)).get(); + ASSERT_EQ(TestService::State::kOne, instance->getInitialState()); + ASSERT_EQ(TestService::State::kOne, instance->getState()); TestServiceHangDuringStateOne.setMode(FailPoint::off); - (*instance)->getCompletionFuture().get(); + instance->getCompletionFuture().get(); } TEST_F(PrimaryOnlyServiceTest, RecreateInstancesFails) { @@ -1034,10 +1011,8 @@ TEST_F(PrimaryOnlyServiceTest, RecreateInstancesFails) { // After stepping down we are in a consistent state again, but cannot create or lookup // instances because we are not primary. auto opCtx = makeOperationContext(); - auto [instance, isPausedOrShutdown] = - TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); - ASSERT_FALSE(instance); - ASSERT_TRUE(isPausedOrShutdown); + ASSERT_FALSE(TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)) + .is_initialized()); ASSERT_THROWS_CODE(TestService::Instance::getOrCreate( opCtx.get(), _service, BSON("_id" << 0 << "state" << 0)), DBException, @@ -1054,15 +1029,13 @@ TEST_F(PrimaryOnlyServiceTest, RecreateInstancesFails) { { // Instance should be recreated successfully. auto opCtx = makeOperationContext(); - auto [instance, isPausedOrShutdown] = - TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)); - ASSERT_TRUE(instance); - ASSERT_FALSE(isPausedOrShutdown); - ASSERT_EQ(TestService::State::kOne, (*instance)->getInitialState()); - ASSERT_EQ(TestService::State::kOne, (*instance)->getState()); + auto instance = + TestService::Instance::lookup(opCtx.get(), _service, BSON("_id" << 0)).get(); + ASSERT_EQ(TestService::State::kOne, instance->getInitialState()); + ASSERT_EQ(TestService::State::kOne, instance->getState()); TestServiceHangDuringStateOne.setMode(FailPoint::off); - (*instance)->getCompletionFuture().get(); - ASSERT_EQ(TestService::State::kDone, (*instance)->getState()); + instance->getCompletionFuture().get(); + ASSERT_EQ(TestService::State::kDone, instance->getState()); } } |
