diff options
Diffstat (limited to 'src/mongo/rpc/op_msg_integration_test.cpp')
-rw-r--r-- | src/mongo/rpc/op_msg_integration_test.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/mongo/rpc/op_msg_integration_test.cpp b/src/mongo/rpc/op_msg_integration_test.cpp index 3c3c46ed63b..c3f285e46c5 100644 --- a/src/mongo/rpc/op_msg_integration_test.cpp +++ b/src/mongo/rpc/op_msg_integration_test.cpp @@ -29,6 +29,8 @@ #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest +#include <fmt/format.h> + #include "mongo/platform/basic.h" #include "mongo/client/dbclient_connection.h" @@ -1283,4 +1285,79 @@ TEST(OpMsg, ServerHandlesReallyLargeMessagesGracefully) { ASSERT_NOT_OK(replyStatus); ASSERT_EQ(replyStatus, ErrorCodes::BSONObjectTooLarge); } + +class HelloOkTest final { +public: + auto connect(boost::optional<bool> helloOk = boost::none) const { + auto connStr = unittest::getFixtureConnectionString(); + + auto swURI = MongoURI::parse(connStr.toString()); + ASSERT_OK(swURI.getStatus()); + + auto uri = swURI.getValue(); + if (helloOk.has_value()) { + uri.setHelloOk(helloOk.get()); + } + + std::string errMsg; + auto conn = connStr.connect(_appName, errMsg, 0, &uri); + uassert(ErrorCodes::SocketException, errMsg, conn); + + _configureFailPoint(conn.get()); + return conn; + } + + auto checkIfClientSupportsHello(DBClientBase* conn) const { + auto checkHelloSupport = [conn](const std::string& helloCommand) { + auto response = + conn->runCommand(OpMsgRequest::fromDBAndBody("admin", BSON(helloCommand << 1))) + ->getCommandReply() + .getOwned(); + auto helloOk = response.getField("clientSupportsHello"); + ASSERT(!helloOk.eoo()); + return helloOk.Bool(); + }; + + auto helloOk = checkHelloSupport("hello"); + ASSERT_EQ(helloOk, checkHelloSupport("isMaster")); + ASSERT_EQ(helloOk, checkHelloSupport("ismaster")); + return helloOk; + } + +private: + void _configureFailPoint(DBClientBase* conn) const { + const auto threadName = getThreadNameByAppName(conn, _appName); + const auto failPointObj = BSON("configureFailPoint" + << "appendHelloOkToHelloResponse" + << "mode" + << "alwaysOn" + << "data" << BSON("threadName" << threadName)); + auto response = conn->runCommand(OpMsgRequest::fromDBAndBody("admin", failPointObj)); + ASSERT_OK(getStatusFromCommandResult(response->getCommandReply())); + } + + static constexpr auto _appName = "integration_test"; +}; + +TEST(OpMsg, HelloOkIsDisabledByDefault) { + HelloOkTest instance; + auto conn = instance.connect(); + auto isHelloOk = instance.checkIfClientSupportsHello(conn.get()); + ASSERT(!isHelloOk); +} + +TEST(OpMsg, HelloOkCanBeEnabled) { + HelloOkTest instance; + auto conn = instance.connect(true); + auto isHelloOk = instance.checkIfClientSupportsHello(conn.get()); + ASSERT(isHelloOk); +} + +TEST(OpMsg, HelloOkCanBeDisabled) { + HelloOkTest instance; + auto conn = instance.connect(false); + auto isHelloOk = instance.checkIfClientSupportsHello(conn.get()); + ASSERT(!isHelloOk); +} + } // namespace mongo |