summaryrefslogtreecommitdiff
path: root/src/mongo/rpc/op_msg_integration_test.cpp
diff options
context:
space:
mode:
authorAmirsaman Memaripour <amirsaman.memaripour@mongodb.com>2020-11-17 17:02:55 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-11-24 22:03:04 +0000
commit091d7cbe42c8a635e1950e597aac68f1feed88c1 (patch)
treebe45ea2d14c20b87aa2104dd6caeaaa9425ffad9 /src/mongo/rpc/op_msg_integration_test.cpp
parent5f72078a11a072b2af8cae30b195038945e49755 (diff)
downloadmongo-091d7cbe42c8a635e1950e597aac68f1feed88c1.tar.gz
SERVER-51812 Allow DBClientConnection::connect() to specify helloOk when initializing a connection
Diffstat (limited to 'src/mongo/rpc/op_msg_integration_test.cpp')
-rw-r--r--src/mongo/rpc/op_msg_integration_test.cpp77
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