This is an automated email from the ASF dual-hosted git repository.

chenBright pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new 11753111 test: wait for submitted spans to be collected (#3448)
11753111 is described below

commit 117531111d74d1afe44f37e49161fdd2c966b72e
Author: Regal <[email protected]>
AuthorDate: Sat Aug 15 09:42:04 2026 +0800

    test: wait for submitted spans to be collected (#3448)
    
    Wait for the asynchronous span collector to release root client spans
    after Controller reset or submission. This prevents LeakSanitizer from
    reporting pending test spans when the short-lived test binary exits
    before the collector’s first polling interval.
    
    Signed-off-by: Zhengwei Zhu <[email protected]>
---
 test/brpc_controller_unittest.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/test/brpc_controller_unittest.cpp 
b/test/brpc_controller_unittest.cpp
index 77de2099..d000d41a 100644
--- a/test/brpc_controller_unittest.cpp
+++ b/test/brpc_controller_unittest.cpp
@@ -42,6 +42,14 @@ void MyCancelCallback(bool* cancel_flag) {
     *cancel_flag = true;
 }
 
+bool WaitForSpanToExpire(const std::weak_ptr<brpc::Span>& span) {
+    const int64_t deadline_us = butil::gettimeofday_us() + 5000000L;
+    while (!span.expired() && butil::gettimeofday_us() < deadline_us) {
+        usleep(1000);
+    }
+    return span.expired();
+}
+
 TEST_F(ControllerTest, notify_on_failed) {
     brpc::SocketId id = 0;
     ASSERT_EQ(0, brpc::Socket::Create(brpc::SocketOptions(), &id));
@@ -94,6 +102,7 @@ TEST_F(ControllerTest, 
root_client_span_kept_alive_until_reset) {
 
     cntl.Reset();
     ASSERT_FALSE(cntl._span);
+    ASSERT_TRUE(WaitForSpanToExpire(weak_span));
 }
 
 TEST_F(ControllerTest, root_client_span_released_by_submit_span) {
@@ -115,6 +124,7 @@ TEST_F(ControllerTest, 
root_client_span_released_by_submit_span) {
 
     cntl.SubmitSpan();
     ASSERT_FALSE(cntl._span);
+    ASSERT_TRUE(WaitForSpanToExpire(weak_span));
 }
 
 #if ! BRPC_WITH_GLOG


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to