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
15 changes: 12 additions & 3 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ jobs:
# real server (e.g. brpc_redis_unittest) actually run under bazel instead
# of skipping. Same shared action the make-based unittest jobs use.
- uses: ./.github/actions/install-essential-dependencies
- run: bazel test --config=rdma --config=ubring //test/...
- run: |
bazel test --test_output=errors \
--local_test_jobs=3 \
--config=rdma \
--config=ubring \
//test/...

gcc-compile-with-bazel-all-options:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -256,7 +261,9 @@ 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 \
--local_test_jobs=3 \
--action_env=CC=clang \
--config=rdma \
--config=ubring \
Expand Down Expand Up @@ -384,7 +391,9 @@ jobs:
grep -qE "bazel_dep\(name = ['\"]protobuf['\"], version = ['\"]${TEST_PROTOBUF_VERSION}['\"]" MODULE.bazel \
|| { echo "ERROR: failed to override protobuf version in MODULE.bazel to ${TEST_PROTOBUF_VERSION}"; exit 1; }
- run: |
bazel test --action_env=CC=clang --config=rdma --config=ubring \
bazel test --test_output=errors \
--local_test_jobs=3 \
--action_env=CC=clang --config=rdma --config=ubring \
--define with_bthread_tracer=true \
--define with_babylon_counter=true \
//test/...
12 changes: 12 additions & 0 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ generate_unittests(
"@com_google_googletest//:gtest_main",
] + TCMALLOC_DEP_UNLESS_ASAN,
copts = COPTS,
per_test_tags = {
"bthread_cond_unittest.cpp": ["exclusive"],
"bthread_fd_unittest.cpp": ["exclusive"],
"bthread_unittest.cpp": ["exclusive"],
},
)

# Expose unit-test data files (cert*, jsonout) at the runfiles workspace root
Expand Down Expand Up @@ -252,8 +257,14 @@ generate_unittests(
# PATH, apt-installed by install-essential-dependencies); tag them the same
# so bazel never serves a cached pass that actually skipped and runs them
# outside the sandbox where mysqld and loopback are visible.
# Run timing-sensitive event-loop and socket tests without competing test
# processes. Their assertions intentionally depend on prompt scheduling.
per_test_tags = {
"brpc_event_dispatcher_unittest.cpp": ["exclusive"],
"brpc_http_rpc_protocol_unittest.cpp": ["exclusive"],
"brpc_redis_unittest.cpp": ["external", "local"],
"brpc_server_unittest.cpp": ["exclusive"],
"brpc_socket_unittest.cpp": ["exclusive"],
"brpc_mysql_auth_handshake_unittest.cpp": ["external", "local"],
"brpc_mysql_connection_type_unittest.cpp": ["external", "local"],
"brpc_mysql_prepared_integration_unittest.cpp": ["external", "local"],
Expand All @@ -274,6 +285,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
6 changes: 2 additions & 4 deletions test/brpc_http_rpc_protocol_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2767,14 +2767,12 @@ void ReadOneResponse(brpc::SocketUniquePtr& sock,
}

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
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) {
}
}
}
}
}
6 changes: 4 additions & 2 deletions test/brpc_server_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1859,19 +1859,21 @@ TEST_F(ServerTest, single_repeated_to_array) {
}

TEST_F(ServerTest, too_big_message) {
GFLAGS_NAMESPACE::FlagSaver flag_saver;
brpc::FLAGS_max_body_size = 1024;
EchoServiceImpl echo_svc;
brpc::Server server;
ASSERT_EQ(0, server.AddService(&echo_svc,
brpc::SERVER_DOESNT_OWN_SERVICE));
ASSERT_EQ(0, server.Start(8613, nullptr));
ASSERT_EQ(0, server.Start(0, nullptr));

#if !BRPC_WITH_GLOG
logging::StringSink log_str;
logging::LogSink* old_sink = logging::SetLogSink(&log_str);
#endif

brpc::Channel chan;
ASSERT_EQ(0, chan.Init("localhost:8613", nullptr));
ASSERT_EQ(0, chan.Init(server.listen_address(), nullptr));
brpc::Controller cntl;
test::EchoRequest req;
test::EchoResponse res;
Expand Down
8 changes: 6 additions & 2 deletions test/endpoint_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ static void test_listen_connect(const std::string& server_addr, const std::strin

int listen_fd = butil::tcp_listen(point);
ASSERT_GT(listen_fd, 0);
if (point.port == 0) {
ASSERT_EQ(0, butil::get_local_side(listen_fd, &point));
}
const std::string actual_server_addr = butil::endpoint2str(point).c_str();
pthread_t pid;
pthread_create(&pid, nullptr, server_proc, (void*)(int64_t)listen_fd);

Expand All @@ -206,7 +210,7 @@ static void test_listen_connect(const std::string& server_addr, const std::strin
ASSERT_EQ(exp_client_addr, s.substr(0, exp_client_addr.size()));
}
ASSERT_EQ(0, butil::get_remote_side(fd, &point2));
ASSERT_EQ(server_addr, butil::endpoint2str(point2).c_str());
ASSERT_EQ(actual_server_addr, butil::endpoint2str(point2).c_str());
close(fd);

void* ret = nullptr;
Expand All @@ -225,7 +229,7 @@ static void test_parse_and_serialize(const std::string& instr, const std::string
}

TEST(EndPointTest, ipv4) {
test_listen_connect("127.0.0.1:8787", "127.0.0.1:");
test_listen_connect("127.0.0.1:0", "127.0.0.1:");
}

TEST(EndPointTest, ipv6) {
Expand Down
Loading