diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 57837ecf4e..07802f8eec 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -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 \ diff --git a/test/BUILD.bazel b/test/BUILD.bazel index 27d63aed81..0845b0bfbf 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -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", }, ) diff --git a/test/brpc_http_rpc_protocol_unittest.cpp b/test/brpc_http_rpc_protocol_unittest.cpp index af2e17bca0..6a0286b410 100644 --- a/test/brpc_http_rpc_protocol_unittest.cpp +++ b/test/brpc_http_rpc_protocol_unittest.cpp @@ -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& imsg_guard) { + brpc::ParseResult pr = brpc::policy::ParseHttpMessage( + read_buf, sock.get(), false, nullptr); + if (pr.is_ok()) { + imsg_guard.reset(static_cast(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(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; @@ -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 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); } diff --git a/test/brpc_interceptor_unittest.cpp b/test/brpc_interceptor_unittest.cpp index ca9ab40f11..98034b5d8c 100644 --- a/test/brpc_interceptor_unittest.cpp +++ b/test/brpc_interceptor_unittest.cpp @@ -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"; @@ -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; @@ -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); } @@ -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; @@ -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); } @@ -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); } @@ -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; @@ -198,4 +197,4 @@ TEST_F(InterceptorTest, sanity) { } } } -} \ No newline at end of file +}