diff options
author | jannaerin <golden.janna@gmail.com> | 2020-04-06 17:07:06 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-04-10 19:01:01 +0000 |
commit | c01d93166f824ecc0aeb57d3f02003d833769fa5 (patch) | |
tree | f3a9176c6f8fc2a8a8adb77042bf7d6670434af3 | |
parent | f5c988bbbcc5251f2ce8726ef399092b037245fe (diff) | |
download | mongo-c01d93166f824ecc0aeb57d3f02003d833769fa5.tar.gz |
SERVER-47361 Add test that TopologyStateMachine checks electionId before updating TopologyDescription
(cherry picked from commit 2729fa173989a90ee8f9b114d1695aea062a43ae)
-rw-r--r-- | src/mongo/client/sdam/topology_state_machine_test.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/mongo/client/sdam/topology_state_machine_test.cpp b/src/mongo/client/sdam/topology_state_machine_test.cpp index cf2036d70fc..d01f48e6c34 100644 --- a/src/mongo/client/sdam/topology_state_machine_test.cpp +++ b/src/mongo/client/sdam/topology_state_machine_test.cpp @@ -458,4 +458,64 @@ TEST_F(TopologyStateMachineTestFixture, ShouldUpdateToCorrectToplogyType) { assertTopologyTypeTestCase(testCase); } } + +TEST_F(TopologyStateMachineTestFixture, ShouldMarkStalePrimaryAsUnknown) { + const auto freshPrimary = (*kTwoSeedReplicaSetNoPrimaryConfig.getSeedList()).front(); + const auto stalePrimary = (*kTwoSeedReplicaSetNoPrimaryConfig.getSeedList()).back(); + + TopologyStateMachine stateMachine(kTwoSeedReplicaSetNoPrimaryConfig); + auto topologyDescription = + std::make_shared<TopologyDescription>(kTwoSeedReplicaSetNoPrimaryConfig); + + const OID oidOne(std::string("000000000000000000000001")); + const OID oidTwo(std::string("000000000000000000000002")); + + auto freshServerDescription = ServerDescriptionBuilder() + .withType(ServerType::kRSPrimary) + .withSetName(*topologyDescription->getSetName()) + .withPrimary(freshPrimary) + .withMe(freshPrimary) + .withAddress(freshPrimary) + .withHost(freshPrimary) + .withHost(stalePrimary) + .withSetVersion(1) + .withElectionId(oidTwo) + .instance(); + + auto secondaryServerDescription = ServerDescriptionBuilder() + .withAddress(stalePrimary) + .withType(ServerType::kRSSecondary) + .withSetName(*topologyDescription->getSetName()) + .instance(); + + stateMachine.onServerDescription(*topologyDescription, freshServerDescription); + stateMachine.onServerDescription(*topologyDescription, secondaryServerDescription); + + ASSERT_EQUALS(topologyDescription->getType(), TopologyType::kReplicaSetWithPrimary); + ASSERT_EQUALS((*topologyDescription->getPrimary())->getAddress(), freshPrimary); + + auto secondaryServer = topologyDescription->findServerByAddress(stalePrimary); + ASSERT_EQUALS((*secondaryServer)->getType(), ServerType::kRSSecondary); + + auto staleServerDescription = ServerDescriptionBuilder() + .withType(ServerType::kRSPrimary) + .withSetName(*topologyDescription->getSetName()) + .withPrimary(stalePrimary) + .withMe(stalePrimary) + .withAddress(stalePrimary) + .withHost(stalePrimary) + .withHost(freshPrimary) + .withSetVersion(1) + .withElectionId(oidOne) + .instance(); + + stateMachine.onServerDescription(*topologyDescription, staleServerDescription); + + ASSERT_EQUALS(topologyDescription->getType(), TopologyType::kReplicaSetWithPrimary); + ASSERT(topologyDescription->getPrimary()); + ASSERT_EQUALS((*topologyDescription->getPrimary())->getAddress(), freshPrimary); + + auto staleServer = topologyDescription->findServerByAddress(stalePrimary); + ASSERT_EQUALS((*staleServer)->getType(), ServerType::kUnknown); +} } // namespace mongo::sdam |