Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ jobs:
# actually run under bazel (see gcc-unittest-with-bazel).
- uses: ./.github/actions/install-essential-dependencies
- run: |
bazel test --test_output=streamed \
# Keep test targets parallel; streamed output forces local serial execution.
bazel test --test_output=errors \
--action_env=CC=clang \
--config=rdma \
--config=ubring \
Expand Down
1 change: 1 addition & 0 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ generate_unittests(
per_test_size = {
"brpc_channel_unittest.cpp": "large",
"brpc_load_balancer_unittest.cpp": "large",
"brpc_protobuf_json_unittest.cpp": "large",
},
)

Expand Down
30 changes: 17 additions & 13 deletions test/brpc_http_rpc_protocol_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2459,45 +2459,48 @@ void MakeHttpRequestHeaders(butil::IOBuf* out,

#undef BRPC_CRLF

void ReadOneResponse(brpc::SocketUniquePtr& sock,
void ReadOneResponse(brpc::SocketUniquePtr& sock, butil::IOPortal* read_buf,
brpc::DestroyingPtr<brpc::policy::HttpContext>& imsg_guard) {
brpc::ParseResult pr = brpc::policy::ParseHttpMessage(
read_buf, sock.get(), false, nullptr);
if (pr.is_ok()) {
imsg_guard.reset(static_cast<brpc::policy::HttpContext*>(pr.message()));
return;
}
ASSERT_EQ(brpc::PARSE_ERROR_NOT_ENOUGH_DATA, pr.error());
#if defined(OS_LINUX)
ASSERT_EQ(0, bthread_fd_wait(sock->fd(), EPOLLIN));
#elif defined(OS_MACOSX)
ASSERT_EQ(0, bthread_fd_wait(sock->fd(), EVFILT_READ));
#endif

butil::IOPortal read_buf;
int64_t start_time = butil::cpuwide_time_us();
while (true) {
const ssize_t nr = read_buf.append_from_file_descriptor(sock->fd(), 4096);
const ssize_t nr = read_buf->append_from_file_descriptor(sock->fd(), 4096);
LOG(INFO) << "nr=" << nr;
LOG(INFO) << butil::ToPrintableString(read_buf);
LOG(INFO) << butil::ToPrintableString(*read_buf);
ASSERT_TRUE(nr > 0 || (nr < 0 && errno == EAGAIN));
if (errno == EAGAIN) {
ASSERT_LT(butil::cpuwide_time_us(), start_time + 1000000L) << "Too long!";
bthread_usleep(1000);
continue;
}
brpc::ParseResult pr = brpc::policy::ParseHttpMessage(&read_buf, sock.get(), false, nullptr);
pr = brpc::policy::ParseHttpMessage(read_buf, sock.get(), false, nullptr);
ASSERT_TRUE(pr.error() == brpc::PARSE_ERROR_NOT_ENOUGH_DATA || pr.is_ok());
if (pr.is_ok()) {
imsg_guard.reset(static_cast<brpc::policy::HttpContext*>(pr.message()));
break;
}
}
ASSERT_TRUE(read_buf.empty());
}

TEST_F(HttpTest, http_expect) {
const int port = 8923;
brpc::Server server;
HttpServiceImpl svc;
EXPECT_EQ(0, server.AddService(&svc, brpc::SERVER_DOESNT_OWN_SERVICE));
EXPECT_EQ(0, server.Start(port, nullptr));
EXPECT_EQ(0, server.Start(0, nullptr));

butil::EndPoint ep;
ASSERT_EQ(0, butil::str2endpoint("127.0.0.1:8923", &ep));
const butil::EndPoint ep = server.listen_address();
brpc::SocketOptions options;
options.remote_side = ep;
brpc::SocketId id;
Expand Down Expand Up @@ -2525,18 +2528,19 @@ TEST_F(HttpTest, http_expect) {
ASSERT_LT(butil::cpuwide_time_us(), start_time + 1000000L) << "Too long!";
}
// 100 Continue
butil::IOPortal read_buf;
brpc::DestroyingPtr<brpc::policy::HttpContext> imsg_guard;
ReadOneResponse(sock, imsg_guard);
ReadOneResponse(sock, &read_buf, imsg_guard);
ASSERT_EQ(imsg_guard->header().status_code(), brpc::HTTP_STATUS_CONTINUE);

ASSERT_EQ(0, sock->Write(&content));
// 200 Ok
ReadOneResponse(sock, imsg_guard);
ReadOneResponse(sock, &read_buf, imsg_guard);
ASSERT_EQ(imsg_guard->header().status_code(), brpc::HTTP_STATUS_OK);

ASSERT_EQ(0, sock->Write(&request_buf));
// 200 Ok
ReadOneResponse(sock, imsg_guard);
ReadOneResponse(sock, &read_buf, imsg_guard);
ASSERT_EQ(imsg_guard->header().status_code(), brpc::HTTP_STATUS_OK);
}

Expand Down
15 changes: 7 additions & 8 deletions test/brpc_interceptor_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ int main(int argc, char* argv[]) {

const int EREJECT = 4000;
int g_index = 0;
const int port = 8613;
const std::string EXP_REQUEST = "hello";
const std::string EXP_RESPONSE = "world";
const std::string NSHEAD_EXP_RESPONSE = "error";
Expand Down Expand Up @@ -108,7 +107,7 @@ class InterceptorTest : public ::testing::Test {
options.interceptor = new MyInterceptor;
options.nshead_service = new MyNsheadProtocol;
options.server_owns_interceptor = true;
EXPECT_EQ(0, _server.Start(port, &options));
EXPECT_EQ(0, _server.Start(0, &options));
}

~InterceptorTest() override = default;
Expand Down Expand Up @@ -143,7 +142,7 @@ TEST_F(InterceptorTest, sanity) {
{
brpc::Channel channel;
brpc::ChannelOptions options;
ASSERT_EQ(0, channel.Init("localhost", port, &options));
ASSERT_EQ(0, channel.Init(_server.listen_address(), &options));
test::EchoService_Stub stub(&channel);
CallMethod(stub, req, res);
}
Expand All @@ -153,7 +152,7 @@ TEST_F(InterceptorTest, sanity) {
brpc::Channel channel;
brpc::ChannelOptions options;
options.protocol = brpc::PROTOCOL_HTTP;
ASSERT_EQ(0, channel.Init("localhost", port, &options));
ASSERT_EQ(0, channel.Init(_server.listen_address(), &options));
test::EchoService_Stub stub(&channel);
// Set the x-bd-error-code header of http response to brpc error code.
brpc::policy::FLAGS_use_http_error_code = true;
Expand All @@ -165,7 +164,7 @@ TEST_F(InterceptorTest, sanity) {
brpc::Channel channel;
brpc::ChannelOptions options;
options.protocol = brpc::PROTOCOL_HULU_PBRPC;
ASSERT_EQ(0, channel.Init("localhost", port, &options));
ASSERT_EQ(0, channel.Init(_server.listen_address(), &options));
test::EchoService_Stub stub(&channel);
CallMethod(stub, req, res);
}
Expand All @@ -175,7 +174,7 @@ TEST_F(InterceptorTest, sanity) {
brpc::Channel channel;
brpc::ChannelOptions options;
options.protocol = brpc::PROTOCOL_SOFA_PBRPC;
ASSERT_EQ(0, channel.Init("localhost", port, &options));
ASSERT_EQ(0, channel.Init(_server.listen_address(), &options));
test::EchoService_Stub stub(&channel);
CallMethod(stub, req, res);
}
Expand All @@ -185,7 +184,7 @@ TEST_F(InterceptorTest, sanity) {
brpc::Channel channel;
brpc::ChannelOptions options;
options.protocol = brpc::PROTOCOL_NSHEAD;
ASSERT_EQ(0, channel.Init("localhost", port, &options));
ASSERT_EQ(0, channel.Init(_server.listen_address(), &options));
brpc::NsheadMessage request;
for (g_index = 0; g_index < 1000; ++g_index) {
brpc::Controller cntl;
Expand All @@ -198,4 +197,4 @@ TEST_F(InterceptorTest, sanity) {
}
}
}
}
}
Loading