Copilot commented on code in PR #3746:
URL: https://github.com/apache/brpc/pull/3746#discussion_r4576773686
##########
test/brpc_flatbuffers_protocol_unittest.cpp:
##########
@@ -2317,4 +2488,14 @@ TEST(FlatBuffersProbeOrderTest,
ProbedRightAfterBaiduStd) {
}
} // namespace
+
+#if BRPC_WITH_RDMA
+int main(int argc, char* argv[]) {
+ testing::InitGoogleTest(&argc, argv);
+ GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
+ brpc::GlobalInitializeOrDie();
+ brpc::rdma::GlobalRdmaInitializeOrDie();
Review Comment:
This unconditionally calls `GlobalRdmaInitializeOrDie()` whenever the
FlatBuffers test is compiled with RDMA. That initializer exits the process when
no RDMA device or verbs library is available, so the entire FlatBuffers
protocol suite—including its TCP/framing tests—cannot run in the normal
compile-with-RDMA/no-hardware configuration. Keep RDMA setup behind an explicit
hardware-test path (or isolate the hardware tests in a separate binary) instead
of initializing it from the common test entry point.
##########
test/brpc_flatbuffers_protocol_unittest.cpp:
##########
@@ -434,6 +463,148 @@ class FlatBuffersProtocolTest : public ::testing::Test {
brpc::Channel channel;
};
+#if BRPC_WITH_RDMA
+class FlatBuffersRdmaTest : public ::testing::Test {
+protected:
+ void StartServer(brpc::SocketMode mode) {
+ ASSERT_EQ(0, server.AddFlatBuffersService(
+ &service, brpc::SERVER_DOESNT_OWN_SERVICE));
+ brpc::ServerOptions options;
+ options.socket_mode = mode;
+ ASSERT_EQ(0, server.Start("127.0.0.1:0", &options));
+ }
+
+ void StartChannel(brpc::SocketMode mode) {
+ brpc::ChannelOptions options;
+ options.protocol = "fb_rpc";
+ options.connection_type = "single";
+ options.socket_mode = mode;
+ options.timeout_ms = 10000;
+ options.connect_timeout_ms = 5000;
+ options.max_retry = 0;
+ ASSERT_EQ(0, channel.Init(server.listen_address(), &options));
+ }
+
+ void TearDown() override {
+ server.Stop(0);
+ server.Join();
+ }
+
+ void CheckTransport(bool expect_rdma) {
+ brpc::SocketUniquePtr socket;
+ ASSERT_EQ(0, brpc::Socket::Address(channel._server_id, &socket));
+ ASSERT_EQ(expect_rdma, IsRdmaOn(socket.get()));
+ if (!expect_rdma && socket->socket_mode() == brpc::SOCKET_MODE_RDMA) {
+ const auto* transport =
+ static_cast<const
brpc::RdmaTransport*>(socket->_transport.get());
+ EXPECT_EQ(brpc::rdma::RdmaEndpoint::FALLBACK_TCP,
+
transport->_rdma_ep->_state.load(butil::memory_order_acquire));
+ EXPECT_EQ(brpc::RdmaTransport::RDMA_OFF, transport->_rdma_state);
+ }
+ }
+
+ void RoundTrips(bool expect_rdma) {
+ const MethodDescriptor* method =
+ service.GetDescriptor()->FindMethodByIndex(41);
+ // The last payload exceeds the RDMA pool's largest block. The tiny
+ // initial builder size also exercises growth, and both peers must
+ // merge multiple receive blocks into an aligned contiguous message.
+ for (size_t size : {0u, 63u, 8193u, 3u * 1024 * 1024 + 17}) {
+ for (bool asynchronous : {false, true}) {
+ SCOPED_TRACE(size);
+ SCOPED_TRACE(asynchronous);
+ const Message request = MakePayload(size, 31, 19);
+ const std::string original = Bytes(request);
+ Message response;
+ brpc::Controller cntl;
+ std::string attachment(std::min<size_t>(size / 3, 131073),
'\0');
+ for (size_t i = 0; i < attachment.size(); ++i) {
+ attachment[i] = static_cast<char>(i % 251);
+ }
+ cntl.request_attachment().append(attachment);
+ Completion done;
+ const int calls_before = service.rdma_calls.load();
+ channel.FBCallMethod(method, &cntl, &request, &response,
+ asynchronous ? &done : nullptr);
+ if (asynchronous) {
+ brpc::Join(cntl.call_id());
+ EXPECT_EQ(1, done.calls());
+ }
+ ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText();
+ ASSERT_NO_FATAL_FAILURE(CheckTransport(expect_rdma));
+ EXPECT_EQ(calls_before + (expect_rdma ? 1 : 0),
+ service.rdma_calls.load());
+ ExpectReply(response, request, method);
+ EXPECT_EQ(attachment, cntl.response_attachment().to_string());
+ EXPECT_EQ(original, Bytes(request));
+ }
+ }
+
+ // Error responses have no application payload. They must complete
+ // sync and async calls over the negotiated transport as well.
+ for (bool asynchronous : {false, true}) {
+ SCOPED_TRACE(asynchronous);
+ const Message request = MakePayload();
+ Message response;
+ brpc::Controller cntl;
+ Completion done;
+ service.fail_next_code = EACCES;
+ const int calls_before = service.rdma_calls.load();
+ channel.FBCallMethod(method, &cntl, &request, &response,
+ asynchronous ? &done : nullptr);
+ if (asynchronous) {
+ brpc::Join(cntl.call_id());
+ EXPECT_EQ(1, done.calls());
+ }
+ ASSERT_EQ(EACCES, cntl.ErrorCode()) << cntl.ErrorText();
+ EXPECT_EQ(0u, response.size());
+ ASSERT_NO_FATAL_FAILURE(CheckTransport(expect_rdma));
+ EXPECT_EQ(calls_before + (expect_rdma ? 1 : 0),
+ service.rdma_calls.load());
+ }
+ }
+
+ PayloadService service;
+ brpc::Server server;
+ brpc::Channel channel;
+};
+
+TEST_F(FlatBuffersRdmaTest, ProtocolAdmissionAndChannelOptions) {
+ EXPECT_TRUE(brpc::rdma::SupportedByRdma("fb_rpc"));
+ EXPECT_TRUE(brpc::rdma::SupportedByRdma("baidu_std"));
+ EXPECT_FALSE(brpc::rdma::SupportedByRdma("http"));
+ ASSERT_NO_FATAL_FAILURE(StartServer(brpc::SOCKET_MODE_TCP));
+ for (const char* connection_type : {"single", "pooled", "short"}) {
+ SCOPED_TRACE(connection_type);
+ brpc::Channel candidate;
+ brpc::ChannelOptions options;
+ options.protocol = "fb_rpc";
+ options.connection_type = connection_type;
+ options.socket_mode = brpc::SOCKET_MODE_RDMA;
+ ASSERT_EQ(0, candidate.Init(server.listen_address(), &options));
+ }
+}
+
+TEST_F(FlatBuffersRdmaTest, RdmaClientFallsBackToTcpServer) {
+ ASSERT_NO_FATAL_FAILURE(StartServer(brpc::SOCKET_MODE_TCP));
+ ASSERT_NO_FATAL_FAILURE(StartChannel(brpc::SOCKET_MODE_RDMA));
+ ASSERT_NO_FATAL_FAILURE(RoundTrips(false));
+}
+
+TEST_F(FlatBuffersRdmaTest, TcpClientCallsRdmaServer) {
+ ASSERT_NO_FATAL_FAILURE(StartServer(brpc::SOCKET_MODE_RDMA));
+ ASSERT_NO_FATAL_FAILURE(StartChannel(brpc::SOCKET_MODE_TCP));
+ ASSERT_NO_FATAL_FAILURE(RoundTrips(false));
+}
+
+TEST_F(FlatBuffersRdmaTest, HardwareRdmaRoundTrips) {
+ ASSERT_TRUE(brpc::rdma::IsRdmaAvailable());
Review Comment:
This assertion makes the standard test fail on any runner without RDMA
hardware. The test is compiled into the regular CMake/Bazel FlatBuffers
unit-test target, so unavailable hardware should skip this integration case (as
the existing RDMA tests gate runtime-only cases) instead of producing a
failure; use `GTEST_SKIP()` when `IsRdmaAvailable()` is false.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]