From 7fdfc3b7f3cecf746b98f5327ce19e25bb1aeff6 Mon Sep 17 00:00:00 2001 From: yexiaochuan Date: Sat, 7 Jun 2025 14:47:40 +0800 Subject: [PATCH 01/11] build(test): generate per-file brpc cc_test to improve Bazel UT coverage Signed-off-by: yexiaochuan --- test/BUILD.bazel | 14 ++++++++++++++ test/brpc_http_rpc_protocol_unittest.cpp | 2 +- test/brpc_unit_test.bzl | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/brpc_unit_test.bzl diff --git a/test/BUILD.bazel b/test/BUILD.bazel index 05420ae310..d4da027ade 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -16,6 +16,7 @@ load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library", "cc_test") load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands") +load("//test:brpc_unit_test.bzl", "generate_brpc_unit_tests") COPTS = [ "-D__STDC_FORMAT_MACROS", @@ -201,6 +202,19 @@ cc_test( ], ) +generate_brpc_unit_tests( + name = "brpc_test", + srcs = glob(["brpc_*_unittest.cpp"]), + copts = COPTS, + deps = [ + ":cc_test_proto", + ":sstream_workaround", + ":gperftools_helper", + "//:brpc", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + ], +) cc_test( name = "bvar_test", diff --git a/test/brpc_http_rpc_protocol_unittest.cpp b/test/brpc_http_rpc_protocol_unittest.cpp index 0eca15326a..dcb4bf5691 100644 --- a/test/brpc_http_rpc_protocol_unittest.cpp +++ b/test/brpc_http_rpc_protocol_unittest.cpp @@ -1128,7 +1128,7 @@ class UploadServiceImpl : public ::test::UploadService { private: void check_header(brpc::Controller* cntl) { const std::string* test_header = cntl->http_request().GetHeader(TEST_PROGRESSIVE_HEADER); - GOOGLE_CHECK_NOTNULL(test_header); + CHECK(test_header != NULL); CHECK_EQ(*test_header, TEST_PROGRESSIVE_HEADER_VAL); } }; diff --git a/test/brpc_unit_test.bzl b/test/brpc_unit_test.bzl new file mode 100644 index 0000000000..39b17c7d3a --- /dev/null +++ b/test/brpc_unit_test.bzl @@ -0,0 +1,16 @@ +def generate_brpc_unit_tests(name, srcs, deps, copts): + tests = [] + for s in srcs: + tgt = s.replace(".cpp", "") + native.cc_test( + name = tgt, + srcs = [s], + copts = copts, + deps = deps, + ) + tests.append(":" + tgt) + + native.test_suite( + name = name, + tests = tests, + ) \ No newline at end of file From 84149dfb394406cd827986e679cdba2a721ae341 Mon Sep 17 00:00:00 2001 From: yexiaochuan Date: Sat, 7 Jun 2025 16:30:01 +0800 Subject: [PATCH 02/11] fix(test): remove deprecated protobuf stubs/logging.h include and add license header Signed-off-by: yexiaochuan --- test/brpc_http_rpc_protocol_unittest.cpp | 1 - test/brpc_unit_test.bzl | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/test/brpc_http_rpc_protocol_unittest.cpp b/test/brpc_http_rpc_protocol_unittest.cpp index dcb4bf5691..12a5f73b7c 100644 --- a/test/brpc_http_rpc_protocol_unittest.cpp +++ b/test/brpc_http_rpc_protocol_unittest.cpp @@ -20,7 +20,6 @@ // Date: Sun Jul 13 15:04:18 CST 2014 #include -#include #include #include #include diff --git a/test/brpc_unit_test.bzl b/test/brpc_unit_test.bzl index 39b17c7d3a..465d107dd3 100644 --- a/test/brpc_unit_test.bzl +++ b/test/brpc_unit_test.bzl @@ -1,3 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + def generate_brpc_unit_tests(name, srcs, deps, copts): tests = [] for s in srcs: From c5f98f9535eabdab496d17e4ea03b5136b9b19be Mon Sep 17 00:00:00 2001 From: yexiaochuan Date: Sat, 7 Jun 2025 18:14:40 +0800 Subject: [PATCH 03/11] fix: replace LOG(NOTICE) with LOG(INFO) in UT for compatibility Signed-off-by: yexiaochuan --- test/brpc_alpn_protocol_unittest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/brpc_alpn_protocol_unittest.cpp b/test/brpc_alpn_protocol_unittest.cpp index 21aada70d6..6c339354ee 100644 --- a/test/brpc_alpn_protocol_unittest.cpp +++ b/test/brpc_alpn_protocol_unittest.cpp @@ -20,12 +20,12 @@ #include "gtest/gtest.h" #include "gflags/gflags.h" - #include "brpc/channel.h" #include "brpc/details/ssl_helper.h" #include "brpc/server.h" #include "butil/endpoint.h" #include "butil/fd_guard.h" +#include "butil/logging.h" #include "echo.pb.h" DEFINE_string(listen_addr, "0.0.0.0:8011", "Server listen address."); @@ -48,7 +48,7 @@ class EchoServerImpl : public test::EchoService { response->set_message(request->message()); brpc::Controller* cntl = static_cast(controller); - LOG(NOTICE) << "protocol:" << cntl->request_protocol(); + LOG(INFO) << "protocol:" << cntl->request_protocol(); } }; From 9e69e6250c4903364f905f54af2dac32ec6efc31 Mon Sep 17 00:00:00 2001 From: yexiaochuan Date: Sun, 10 Aug 2025 16:04:46 +0800 Subject: [PATCH 04/11] add bazel unittest in CI --- .github/workflows/ci-linux.yml | 20 ++++++++++++++++++++ test/BUILD.bazel | 13 +++++++++++++ test/brpc_unit_test.bzl | 3 ++- test/flat_runfiles.bzl | 12 ++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 test/flat_runfiles.bzl diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index dbceac1a51..feb54ae1c5 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -169,6 +169,26 @@ jobs: - uses: actions/checkout@v2 - run: bazel build --verbose_failures --action_env=CC=clang --define with_mesalink=false --define with_glog=true --define with_thrift=true --define with_debug_bthread_sche_safety=true --define with_debug_lock=true --define with_asan=true -- //... -//example/... + gcc-bazel-unittest: + runs-on: ubuntu-22.04 + env: + HTTP_PROXY: http://127.0.0.1:7890 # 假设代理端口是7890 + HTTPS_PROXY: http://127.0.0.1:7890 + NO_PROXY: localhost,127.0.0.1 + steps: + - uses: actions/checkout@v2 + # - uses: bazelbuild/setup-bazelisk@v2 + - name: run bazel tests + run: bazel test --test_output=errors --verbose_failures -- //test/... + + clang-bazel-unittest: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + - uses: bazelbuild/setup-bazelisk@v2 + - name: run bazel tests + run: bazel test --test_output=errors --verbose_failures --action_env=CC=clang -- //test/... //... + clang-unittest: runs-on: ubuntu-22.04 steps: diff --git a/test/BUILD.bazel b/test/BUILD.bazel index d4da027ade..71fa6e0599 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -17,6 +17,18 @@ load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library", "cc_test") load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands") load("//test:brpc_unit_test.bzl", "generate_brpc_unit_tests") +load("//test:flat_runfiles.bzl", "flat_runfiles") + +flat_runfiles( + name = "root_test_assets", + srcs = [ + "cert1.crt", + "cert1.key", + "cert2.crt", + "cert2.key", + "jsonout", + ], +) COPTS = [ "-D__STDC_FORMAT_MACROS", @@ -206,6 +218,7 @@ generate_brpc_unit_tests( name = "brpc_test", srcs = glob(["brpc_*_unittest.cpp"]), copts = COPTS, + data = [":root_test_assets"], deps = [ ":cc_test_proto", ":sstream_workaround", diff --git a/test/brpc_unit_test.bzl b/test/brpc_unit_test.bzl index 465d107dd3..b25f66d0bc 100644 --- a/test/brpc_unit_test.bzl +++ b/test/brpc_unit_test.bzl @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -def generate_brpc_unit_tests(name, srcs, deps, copts): +def generate_brpc_unit_tests(name, srcs, deps, copts, data = []): tests = [] for s in srcs: tgt = s.replace(".cpp", "") @@ -21,6 +21,7 @@ def generate_brpc_unit_tests(name, srcs, deps, copts): name = tgt, srcs = [s], copts = copts, + data = data, deps = deps, ) tests.append(":" + tgt) diff --git a/test/flat_runfiles.bzl b/test/flat_runfiles.bzl new file mode 100644 index 0000000000..6ff8f2a1d6 --- /dev/null +++ b/test/flat_runfiles.bzl @@ -0,0 +1,12 @@ +def _flat_runfiles_impl(ctx): + r = ctx.runfiles() + for f in ctx.files.srcs: + r = r.merge(ctx.runfiles(symlinks = {f.basename: f})) + return DefaultInfo(runfiles = r) + +flat_runfiles = rule( + implementation = _flat_runfiles_impl, + attrs = { + "srcs": attr.label_list(allow_files = True), + }, +) From e141cd2b7e550a774cd0976bc4fe10604107b4fe Mon Sep 17 00:00:00 2001 From: yexiaochuan Date: Sun, 10 Aug 2025 16:19:17 +0800 Subject: [PATCH 05/11] add bzl file license --- test/flat_runfiles.bzl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/flat_runfiles.bzl b/test/flat_runfiles.bzl index 6ff8f2a1d6..807e31ebc5 100644 --- a/test/flat_runfiles.bzl +++ b/test/flat_runfiles.bzl @@ -1,3 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + def _flat_runfiles_impl(ctx): r = ctx.runfiles() for f in ctx.files.srcs: From 2352719eb2940eb0f9f80e92d42f12ebb96ab1f1 Mon Sep 17 00:00:00 2001 From: yexiaochuan Date: Mon, 18 Aug 2025 12:48:12 +0800 Subject: [PATCH 06/11] fix redundant env --- .github/workflows/ci-linux.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index feb54ae1c5..b1cafe5600 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -171,13 +171,8 @@ jobs: gcc-bazel-unittest: runs-on: ubuntu-22.04 - env: - HTTP_PROXY: http://127.0.0.1:7890 # 假设代理端口是7890 - HTTPS_PROXY: http://127.0.0.1:7890 - NO_PROXY: localhost,127.0.0.1 steps: - uses: actions/checkout@v2 - # - uses: bazelbuild/setup-bazelisk@v2 - name: run bazel tests run: bazel test --test_output=errors --verbose_failures -- //test/... From 69169934f37abf2c7a3ff7e5874a61d71d835953 Mon Sep 17 00:00:00 2001 From: yexiaochuan Date: Sun, 31 Aug 2025 11:53:27 +0800 Subject: [PATCH 07/11] ci: drop setup-bazelisk action (not allowed in Apache) Signed-off-by: yexiaochuan --- .github/workflows/ci-linux.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index f3232bc7cb..caa4695b08 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -180,7 +180,6 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - - uses: bazelbuild/setup-bazelisk@v2 - name: run bazel tests run: bazel test --test_output=errors --verbose_failures --action_env=CC=clang -- //test/... //... From 5cc61f2b9e81538798482e62f7b202a3c2a0695f Mon Sep 17 00:00:00 2001 From: yexiaochuan Date: Sun, 31 Aug 2025 12:19:25 +0800 Subject: [PATCH 08/11] fix clang-bazel-unittest command --- .github/workflows/ci-linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index caa4695b08..54e5129d20 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -181,7 +181,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: run bazel tests - run: bazel test --test_output=errors --verbose_failures --action_env=CC=clang -- //test/... //... + run: bazel test --test_output=errors --verbose_failures --action_env=CC=clang -- //test/... clang-unittest: runs-on: ubuntu-22.04 From f0491a8a70c060c38da993987574c5c1decfeeb2 Mon Sep 17 00:00:00 2001 From: yexiaochuan Date: Sun, 31 Aug 2025 17:14:18 +0800 Subject: [PATCH 09/11] fix clang bazel unittest ci with clang12 --- .github/workflows/ci-linux.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 54e5129d20..4920a9fa45 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -180,6 +180,9 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 + - run: | + sudo apt-get update && sudo apt-get install -y clang-12 lldb-12 lld-12 libgtest-dev cmake gdb libstdc++6-11-dbg + shell: bash - name: run bazel tests run: bazel test --test_output=errors --verbose_failures --action_env=CC=clang -- //test/... From 6fa0ce9bcc24ab3841e795ec53ae722c0cf94226 Mon Sep 17 00:00:00 2001 From: yexiaochuan Date: Sun, 31 Aug 2025 21:44:50 +0800 Subject: [PATCH 10/11] increase bazel test timeout to 900s --- .github/workflows/ci-linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 4920a9fa45..b35be9ce3b 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -174,7 +174,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: run bazel tests - run: bazel test --test_output=errors --verbose_failures -- //test/... + run: bazel test --test_output=errors --verbose_failures --test_timeout=900 -- //test/... clang-bazel-unittest: runs-on: ubuntu-22.04 From fdec07df885e7912f58a88edef30bff8badb93ff Mon Sep 17 00:00:00 2001 From: yexiaochuan Date: Sun, 31 Aug 2025 23:43:35 +0800 Subject: [PATCH 11/11] ci: run bazel tests with clang-12 and disable glog --- .github/workflows/ci-linux.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index b35be9ce3b..3bc86ea90c 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -174,7 +174,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: run bazel tests - run: bazel test --test_output=errors --verbose_failures --test_timeout=900 -- //test/... + run: bazel test --test_output=errors --verbose_failures --test_timeout=900 --define=with_glog=false --define=BRPC_WITH_GLOG=false -- //test/... clang-bazel-unittest: runs-on: ubuntu-22.04 @@ -184,7 +184,7 @@ jobs: sudo apt-get update && sudo apt-get install -y clang-12 lldb-12 lld-12 libgtest-dev cmake gdb libstdc++6-11-dbg shell: bash - name: run bazel tests - run: bazel test --test_output=errors --verbose_failures --action_env=CC=clang -- //test/... + run: bazel test --test_output=errors --verbose_failures --action_env=CC=clang-12 --define=with_glog=false --define=BRPC_WITH_GLOG=false -- //test/... clang-unittest: runs-on: ubuntu-22.04