This is an automated email from the ASF dual-hosted git repository.
wasphin 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 0c42a0c9 Fix flaky histogram window test (#3567)
0c42a0c9 is described below
commit 0c42a0c9591265b72e688a0d8e309ac891e9c856
Author: Bright Chen <[email protected]>
AuthorDate: Sat Sep 26 19:25:34 2026 +0800
Fix flaky histogram window test (#3567)
---
test/bvar_histogram_unittest.cpp | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/test/bvar_histogram_unittest.cpp b/test/bvar_histogram_unittest.cpp
index f5a83c5d..49fc4267 100644
--- a/test/bvar_histogram_unittest.cpp
+++ b/test/bvar_histogram_unittest.cpp
@@ -703,14 +703,20 @@ TEST_F(HistogramTest, window) {
bvar::Histogram h(bvar::Histogram::BucketSchema({0.5, 1.5, 3.0}));
bvar::Window<bvar::Histogram> w(&h, 10);
- h << 0.25 << 1.25;
- sleep(1);
- h << 2.5;
- // One more second so that get_value() has a sample taken after the last
- // value, to diff against the construction-time baseline.
- sleep(1);
-
- bvar::Histogram::Value wv = w.get_value();
+ h << 0.25 << 1.25 << 2.5;
+
+ // Window values are produced by the global sampler thread. Wait until it
+ // observes all writes instead of assuming a fixed sleep covers a sampling
+ // round, which is not guaranteed when the test host is busy.
+ bvar::Histogram::Value wv;
+ for (int i = 0; i < 50; ++i) {
+ wv = w.get_value();
+ if (wv.num == 3) {
+ break;
+ }
+ usleep(100 * 1000);
+ }
+
// Everything recorded, all of it inside the window.
ASSERT_EQ(3, wv.num);
ASSERT_DOUBLE_EQ(4.0, wv.sum);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]