Skip to content

Commit 8a2dc92

Browse files
committed
add UT
1 parent 4aac92d commit 8a2dc92

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

test/brpc_server_unittest.cpp

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2070,4 +2070,50 @@ TEST_F(ServerTest, auth) {
20702070
ASSERT_EQ(0, server.Join());
20712071
}
20722072

2073-
} //namespace
2073+
void TestClientHost(const butil::EndPoint& ep,
2074+
brpc::Controller& cntl,
2075+
int error_code, bool failed,
2076+
brpc::ChannelOptions& copt) {
2077+
brpc::Channel chan;
2078+
copt.max_retry = 0;
2079+
ASSERT_EQ(0, chan.Init(ep, &copt));
2080+
2081+
test::EchoRequest req;
2082+
test::EchoResponse res;
2083+
req.set_message(EXP_REQUEST);
2084+
test::EchoService_Stub stub(&chan);
2085+
stub.Echo(&cntl, &req, &res, NULL);
2086+
ASSERT_EQ(cntl.Failed(), failed) << cntl.ErrorText();
2087+
ASSERT_EQ(cntl.ErrorCode(), error_code);
2088+
}
2089+
2090+
TEST_F(ServerTest, client_host)
2091+
{
2092+
butil::EndPoint ep;
2093+
ASSERT_EQ(0, str2endpoint("127.0.0.1:8613", &ep));
2094+
brpc::Server server;
2095+
EchoServiceImpl service;
2096+
ASSERT_EQ(0, server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE));
2097+
brpc::ServerOptions opt;
2098+
ASSERT_EQ(0, server.Start(ep, &opt));
2099+
2100+
brpc::Controller cntl;
2101+
brpc::ChannelOptions copt;
2102+
copt.client_host = "localhost";
2103+
std::vector<brpc::ConnectionType> connection_types = {
2104+
brpc::CONNECTION_TYPE_SINGLE,
2105+
brpc::CONNECTION_TYPE_POOLED,
2106+
brpc::CONNECTION_TYPE_SHORT
2107+
};
2108+
for (auto connect_type : connection_types)
2109+
{
2110+
copt.connection_type = connect_type;
2111+
TestClientHost(ep, cntl, 0, false, copt);
2112+
cntl.Reset();
2113+
}
2114+
2115+
ASSERT_EQ(0, server.Stop(0));
2116+
ASSERT_EQ(0, server.Join());
2117+
}
2118+
2119+
} // namespace

0 commit comments

Comments
 (0)