diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2020-02-18 14:22:47 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2020-02-18 14:22:47 +0000 |
commit | a6eb455263a437335534a0924a6d0863fc383274 (patch) | |
tree | 8e2ce87939637847b6f7369a6bb818f1c11f5031 | |
parent | 811b695a37c8c1469b4f6475e62c9a6680b3d95f (diff) | |
download | mongo-a6eb455263a437335534a0924a6d0863fc383274.tar.gz |
SERVER-45422 Test that all isMaster fields respect the horizon
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl_test.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp index 1f1e6c32160..b7fba917f79 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp @@ -3250,6 +3250,76 @@ TEST_F(ReplCoordTest, AwaitIsMasterResponseReturnsOnStepDown) { getIsMasterThread.join(); } +TEST_F(ReplCoordTest, AllIsMasterFieldsRespectHorizon) { + init(); + const auto primaryHostName = "node1:12345"; + const auto primaryHostNameHorizon = "horizon.com:15"; + const auto passiveHostName = "node2:12345"; + const auto passiveHostNameHorizon = "horizon.com:16"; + const auto arbiterHostName = "node3:12345"; + const auto arbiterHostNameHorizon = "horizon.com:17"; + assertStartSuccess( + BSON("_id" + << "mySet" + << "version" << 1 << "members" + << BSON_ARRAY(BSON("host" << primaryHostName << "_id" << 1 << "horizons" + << BSON("horizon" << primaryHostNameHorizon)) + << BSON("host" << passiveHostName << "_id" << 2 << "horizons" + << BSON("horizon" << passiveHostNameHorizon) << "priority" + << 0) + << BSON("host" << arbiterHostName << "_id" << 3 << "horizons" + << BSON("horizon" << arbiterHostNameHorizon) + << "arbiterOnly" << true))), + HostAndPort(primaryHostName)); + + // Become primary. + ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); + replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100)); + replCoordSetMyLastDurableOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100)); + simulateSuccessfulV1Election(); + ASSERT(getReplCoord()->getMemberState().primary()); + + auto opCtx = makeOperationContext(); + + // When no horizon is specified, the isMaster response uses the default horizon. + { + HostAndPort primaryHostAndPort(primaryHostName); + HostAndPort passiveHostAndPort(passiveHostName); + HostAndPort arbiterHostAndPort(arbiterHostName); + + const auto response = + getReplCoord()->awaitIsMasterResponse(opCtx.get(), {}, boost::none, boost::none); + const auto hosts = response->getHosts(); + ASSERT_EQUALS(hosts[0], primaryHostAndPort); + ASSERT_EQUALS(response->getPrimary(), primaryHostAndPort); + ASSERT_EQUALS(response->getMe(), primaryHostAndPort); + const auto passives = response->getPassives(); + ASSERT_EQUALS(passives[0], passiveHostAndPort); + const auto arbiters = response->getArbiters(); + ASSERT_EQUALS(arbiters[0], arbiterHostAndPort); + } + + // The isMaster response respects the requested horizon. + { + HostAndPort primaryHostAndPort(primaryHostNameHorizon); + HostAndPort passiveHostAndPort(passiveHostNameHorizon); + HostAndPort arbiterHostAndPort(arbiterHostNameHorizon); + + const std::string horizonSniName = "horizon.com"; + const auto horizon = SplitHorizon::Parameters(horizonSniName); + const auto response = + getReplCoord()->awaitIsMasterResponse(opCtx.get(), horizon, boost::none, boost::none); + const auto hosts = response->getHosts(); + ASSERT_EQUALS(hosts[0], primaryHostAndPort); + ASSERT_EQUALS(response->getPrimary(), primaryHostAndPort); + ASSERT_EQUALS(response->getMe(), primaryHostAndPort); + const auto passives = response->getPassives(); + ASSERT_EQUALS(passives[0], passiveHostAndPort); + const auto arbiters = response->getArbiters(); + ASSERT_EQUALS(arbiters[0], arbiterHostAndPort); + } +} + TEST_F(ReplCoordTest, AwaitIsMasterResponseReturnsErrorOnHorizonChange) { init(); assertStartSuccess(BSON("_id" |