summaryrefslogtreecommitdiff
path: root/src/mongo/client/server_ping_monitor_test.cpp
diff options
context:
space:
mode:
authorHaley Connelly <haley.connelly@mongodb.com>2020-03-27 13:47:34 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-27 18:02:58 +0000
commit4aa3ad525c1012fe9e3dbcb6e0d79745a5446cf5 (patch)
treec1b973f50c9aa9b734a1d643b692515413a7cd98 /src/mongo/client/server_ping_monitor_test.cpp
parentfb09428156a33be70d30452fb3bb91f73be94ee7 (diff)
downloadmongo-4aa3ad525c1012fe9e3dbcb6e0d79745a5446cf5.tar.gz
Revert "SERVER-46681 Integrate the ServerPingMonitor into the StreamableReplicaSetMonitor"
This reverts commit 6694a0434f37db0d6671d05e37a54e78eb1f156b.
Diffstat (limited to 'src/mongo/client/server_ping_monitor_test.cpp')
-rw-r--r--src/mongo/client/server_ping_monitor_test.cpp56
1 files changed, 11 insertions, 45 deletions
diff --git a/src/mongo/client/server_ping_monitor_test.cpp b/src/mongo/client/server_ping_monitor_test.cpp
index 0eba77e7941..05a7f0603d0 100644
--- a/src/mongo/client/server_ping_monitor_test.cpp
+++ b/src/mongo/client/server_ping_monitor_test.cpp
@@ -33,7 +33,7 @@
#include <memory>
-#include "mongo/client/sdam/sdam.h"
+#include "mongo/client/sdam/sdam_datatypes.h"
#include "mongo/client/sdam/topology_listener_mock.h"
#include "mongo/client/server_ping_monitor.h"
#include "mongo/dbtests/mock/mock_replica_set.h"
@@ -161,10 +161,8 @@ protected:
ASSERT_TRUE(_topologyListener->hasPingResponse(hostAndPort));
ASSERT_LT(elapsed(), deadline);
auto pingResponse = _topologyListener->getPingResponse(hostAndPort);
+ ASSERT(pingResponse.isOK());
- // There should only be one isMaster response queued up.
- ASSERT_EQ(pingResponse.size(), 1);
- ASSERT(pingResponse[0].isOK());
checkNoActivityBefore(deadline, hostAndPort);
}
@@ -180,40 +178,6 @@ protected:
}
}
- /**
- * Since the SingleServerPingMonitor is removed upon an onTopologyDescriptionChangedEvent,
- * prompt the event with a new TopologyDescription that does not include hostToDrop.
- */
- void closeMonitor(MockReplicaSet* replSet,
- sdam::ServerAddress hostToDrop,
- ServerPingMonitor* pingMonitor) {
- auto hostAndPorts = replSet->getHosts();
- std::vector<sdam::ServerAddress> hosts;
- std::transform(hostAndPorts.begin(),
- hostAndPorts.end(),
- std::back_inserter(hosts),
- [](const auto& hostAndPort) { return hostAndPort.toString(); });
-
- auto sdamConfigOld = sdam::SdamConfiguration(hosts);
- auto topologyDescriptionOld = std::make_shared<sdam::TopologyDescription>(sdamConfigOld);
-
-
- std::vector<sdam::ServerAddress> hostsNew(hosts.begin(), hosts.end());
- hostsNew.erase(std::remove_if(hostsNew.begin(),
- hostsNew.end(),
- [&](auto host) { return host == hostToDrop; }),
- hostsNew.end());
- // Since the seedlist cannot be empty, the new TopologyDescription contains an empty
- // HostAndPort.
- if (hostsNew.size() == 0) {
- hostsNew.emplace_back(HostAndPort().toString());
- }
- auto sdamConfigNew = sdam::SdamConfiguration(hostsNew);
- auto topologyDescriptionNew = std::make_shared<sdam::TopologyDescription>(sdamConfigNew);
- pingMonitor->onTopologyDescriptionChangedEvent(
- UUID::gen(), topologyDescriptionOld, topologyDescriptionNew);
- }
-
private:
Date_t _startDate;
std::unique_ptr<sdam::TopologyListenerMock> _topologyListener;
@@ -313,8 +277,7 @@ TEST_F(SingleServerPingMonitorTest, pingDeadServer) {
ASSERT_TRUE(topologyListener->hasPingResponse(hostAndPort));
auto pingResponse = topologyListener->getPingResponse(hostAndPort);
- ASSERT_EQ(pingResponse.size(), 1);
- ASSERT_EQ(ErrorCodes::HostUnreachable, pingResponse[0].getStatus());
+ ASSERT_EQ(ErrorCodes::HostUnreachable, pingResponse.getStatus());
checkNoActivityBefore(deadline);
};
@@ -347,13 +310,14 @@ TEST_F(SingleServerPingMonitorTest, noPingAfterSingleServerPingMonitorClosed) {
class ServerPingMonitorTest : public ServerPingMonitorTestFixture {
protected:
std::unique_ptr<ServerPingMonitor> makeServerPingMonitor(Seconds pingFrequency) {
- return std::make_unique<ServerPingMonitor>(
- getTopologyListener(), pingFrequency, getExecutor());
+ auto executor = boost::optional<std::shared_ptr<executor::TaskExecutor>>(getExecutor());
+ return std::make_unique<ServerPingMonitor>(getTopologyListener(), pingFrequency, executor);
}
};
/**
- * Adds and removes a SingleServerPingMonitor from the ServerPingMonitor.
+ * Adds and removes a SingleServerPingMonitor from the ServerPingMonitor via
+ * onServerHandshakeCompleteEvent and onServerClosedEvent.
*/
TEST_F(ServerPingMonitorTest, singleNodeServerPingMonitorCycle) {
auto pingFrequency = Seconds(10);
@@ -362,6 +326,7 @@ TEST_F(ServerPingMonitorTest, singleNodeServerPingMonitorCycle) {
"test", 1, /* hasPrimary = */ false, /* dollarPrefixHosts = */ false);
auto hostAndPort = HostAndPort(replSet->getSecondaries()[0]).toString();
+ auto oid = OID::gen();
// Add a SingleServerPingMonitor to the ServerPingMonitor. Confirm pings are sent to the server
// at pingFrequency.
@@ -371,7 +336,7 @@ TEST_F(ServerPingMonitorTest, singleNodeServerPingMonitorCycle) {
// Close the SingleServerMonitor before the third ping and confirm ping activity to the server
// is stopped.
- closeMonitor(replSet.get(), hostAndPort, serverPingMonitor.get());
+ serverPingMonitor->onServerClosedEvent(hostAndPort, oid);
checkNoActivityBefore(elapsed() + pingFrequency * 2, hostAndPort);
}
@@ -388,6 +353,7 @@ TEST_F(ServerPingMonitorTest, twoNodeServerPingMonitorOneClosed) {
auto hosts = replSet->getHosts();
auto host0 = hosts[0].toString();
auto host1 = hosts[1].toString();
+ auto oid0 = OID::gen();
// Add SingleServerPingMonitors for host0 and host1 where host1 is added host1Delay seconds
// after host0.
@@ -398,7 +364,7 @@ TEST_F(ServerPingMonitorTest, twoNodeServerPingMonitorOneClosed) {
serverPingMonitor->onServerHandshakeCompleteEvent(initialRTT, host1);
checkSinglePing(pingFrequency - Seconds(2), host1, replSet.get());
- closeMonitor(replSet.get(), host0, serverPingMonitor.get());
+ serverPingMonitor->onServerClosedEvent(host0, oid0);
checkNoActivityBefore(pingFrequency + host1Delay, host0);
// Confirm that host1's SingleServerPingMonitor continues ping activity.