summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Wangensteen <george.wangensteen@mongodb.com>2022-09-28 19:27:53 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-09-28 20:19:41 +0000
commit399f53383e7d753329b8cee64df9aaa734e44ec4 (patch)
tree8a668bb13a607222be120941f14f1ef5a1450cc1
parenta6cb05b658ea5ce9a6e7c335339901dfd9ff0f65 (diff)
downloadmongo-399f53383e7d753329b8cee64df9aaa734e44ec4.tar.gz
SERVER-68767 Make RemoteCommandRunner use owning IDL parser
-rw-r--r--src/mongo/executor/hedged_remote_command_runner_test.cpp8
-rw-r--r--src/mongo/executor/remote_command_runner.h4
-rw-r--r--src/mongo/executor/remote_command_runner_test.cpp28
3 files changed, 35 insertions, 5 deletions
diff --git a/src/mongo/executor/hedged_remote_command_runner_test.cpp b/src/mongo/executor/hedged_remote_command_runner_test.cpp
index b879d5a2a02..289dd2c6b21 100644
--- a/src/mongo/executor/hedged_remote_command_runner_test.cpp
+++ b/src/mongo/executor/hedged_remote_command_runner_test.cpp
@@ -151,6 +151,7 @@ TEST_F(HedgedCommandRunnerTest, FindHedgeRequestTwoHosts) {
ASSERT_EQ(counters.canceled, 1);
+ ASSERT_BSONOBJ_EQ(res.response.getCursor()->getFirstBatch()[0], BSON("x" << 1));
ASSERT_EQ(res.response.getCursor()->getNs(), NamespaceString("testdb", "testcoll"));
}
@@ -185,7 +186,7 @@ TEST_F(HedgedCommandRunnerTest, FindHedgeRequestThreeHosts) {
ASSERT_EQ(counters.succeeded, 1);
ASSERT_EQ(counters.canceled, 2);
- // TODO SERVER-68767: ASSERT on actual BSONObj from getFirstBatch()
+ ASSERT_BSONOBJ_EQ(res.response.getCursor()->getFirstBatch()[0], BSON("x" << 1));
ASSERT_EQ(res.response.getCursor()->getNs(), NamespaceString("testdb", "testcoll"));
}
@@ -464,8 +465,9 @@ TEST_F(HedgedCommandRunnerTest, FirstCommandFailsWithSkippableErrorNextSucceeds)
ASSERT_EQ(counters.succeeded, 2);
ASSERT_EQ(counters.canceled, 0);
- ASSERT_EQ(resultFuture.get().response.getCursor()->getNs(),
- NamespaceString("testdb", "testcoll"));
+ auto res = std::move(resultFuture).get().response;
+ ASSERT_EQ(res.getCursor()->getNs(), NamespaceString("testdb", "testcoll"));
+ ASSERT_BSONOBJ_EQ(res.getCursor()->getFirstBatch()[0], BSON("x" << 1));
}
} // namespace
diff --git a/src/mongo/executor/remote_command_runner.h b/src/mongo/executor/remote_command_runner.h
index 98ed870b90f..d796defc4bc 100644
--- a/src/mongo/executor/remote_command_runner.h
+++ b/src/mongo/executor/remote_command_runner.h
@@ -119,8 +119,8 @@ SemiFuture<RemoteCommandRunnerResponse<typename CommandType::Reply>> doRequest(
return std::move(resFuture)
.then([](detail::RemoteCommandInternalResponse r) {
// TODO SERVER-67661: Make IDL reply types have string representation for logging
- auto res =
- CommandType::Reply::parse(IDLParserContext("RemoteCommandRunner"), r.response);
+ auto res = CommandType::Reply::parseSharingOwnership(
+ IDLParserContext("RemoteCommandRunner"), r.response);
struct RemoteCommandRunnerResponse<typename CommandType::Reply> fullRes = {
res, r.targetUsed
diff --git a/src/mongo/executor/remote_command_runner_test.cpp b/src/mongo/executor/remote_command_runner_test.cpp
index d4560933e3c..7f2e83e4935 100644
--- a/src/mongo/executor/remote_command_runner_test.cpp
+++ b/src/mongo/executor/remote_command_runner_test.cpp
@@ -28,6 +28,8 @@
*/
#include "mongo/bson/oid.h"
+#include "mongo/db/query/cursor_response.h"
+#include "mongo/db/query/find_command_gen.h"
#include "mongo/db/repl/hello_gen.h"
#include "mongo/executor/network_test_env.h"
#include "mongo/executor/remote_command_response.h"
@@ -144,6 +146,32 @@ TEST_F(RemoteCommandRunnerTestFixture, RemoteError) {
ASSERT_EQ(remoteError.getRemoteCommandFirstWriteError(), Status::OK());
}
+TEST_F(RemoteCommandRunnerTestFixture, SuccessfulFind) {
+ std::unique_ptr<RemoteCommandHostTargeter> targeter =
+ std::make_unique<RemoteCommandLocalHostTargeter>();
+ auto opCtxHolder = makeOperationContext();
+ DatabaseName testDbName = DatabaseName("testdb", boost::none);
+ NamespaceString nss(testDbName);
+
+ FindCommandRequest findCmd(nss);
+ auto resultFuture = doRequest(
+ findCmd, opCtxHolder.get(), std::move(targeter), getExecutorPtr(), _cancellationToken);
+
+ onCommand([&](const auto& request) {
+ ASSERT(request.cmdObj["find"]);
+ // The BSON documents in this cursor response are created here.
+ // When the remote_command_runner parses the response, it participates
+ // in ownership of the underlying data, so it will participate in
+ // owning the data in the cursor response.
+ return CursorResponse(nss, 0LL, {BSON("x" << 1)})
+ .toBSON(CursorResponse::ResponseType::InitialResponse);
+ });
+
+ CursorInitialReply res = std::move(resultFuture).get().response;
+
+ ASSERT_BSONOBJ_EQ(res.getCursor()->getFirstBatch()[0], BSON("x" << 1));
+}
+
/*
* Mock write concern error on remote host.
*/