Copilot commented on code in PR #3581:
URL: https://github.com/apache/brpc/pull/3581#discussion_r4180851475
##########
test/bvar_multi_dimension_unittest.cpp:
##########
@@ -420,17 +410,24 @@ TEST_F(MultiDimensionTest, mlatencyrecorder) {
bvar::LatencyRecorder* my_latencyrecorder =
my_mlatencyrecorder.get_stats(labels_value);
ASSERT_TRUE(my_latencyrecorder);
*my_latencyrecorder << 1 << 2 << 3 << 4 << 5 << 6 << 7;
- sleep(1);
- ASSERT_EQ(4, my_latencyrecorder->latency());
- ASSERT_EQ(7, my_latencyrecorder->max_latency());
- ASSERT_LE(7, my_latencyrecorder->qps());
- ASSERT_EQ(7, my_latencyrecorder->count());
-
- GFLAGS_NAMESPACE::SetCommandLineOption("bvar_dump_interval",
old_bvar_dump_interval.c_str());
- GFLAGS_NAMESPACE::SetCommandLineOption("mbvar_dump",
old_mbvar_dump.c_str());
- GFLAGS_NAMESPACE::SetCommandLineOption("bvar_latency_p1",
old_bvar_latency_p1.c_str());
- GFLAGS_NAMESPACE::SetCommandLineOption("bvar_latency_p2",
old_bvar_latency_p2.c_str());
- GFLAGS_NAMESPACE::SetCommandLineOption("bvar_latency_p3",
old_bvar_latency_p3.c_str());
+ EXPECT_EQ(7, my_latencyrecorder->count());
+
+ // Sampling runs once per second. Allow five seconds for scheduling
+ // delays on busy CI runners while keeping the wait bounded.
+ const int64_t sampling_timeout_us = 5 * 1000000L;
+ const int64_t deadline =
+ butil::monotonic_time_us() + sampling_timeout_us;
+ while ((my_latencyrecorder->latency() == 0 ||
+ my_latencyrecorder->max_latency() == 0) &&
+ butil::monotonic_time_us() < deadline) {
+ usleep(10000);
+ }
+
+ EXPECT_EQ(4, my_latencyrecorder->latency());
+ EXPECT_EQ(7, my_latencyrecorder->max_latency());
+ // QPS uses the actual sampling interval and randomized rounding.
+ // Seven requests can yield fewer than seven requests per second.
+ EXPECT_GT(my_latencyrecorder->qps(), 0);
Review Comment:
These post-loop reads are not the values that satisfied the polling
condition. With a one-second window and no further writes, the next sampler
tick makes `max_latency()` and `qps()` zero; if this test is descheduled after
leaving the loop, the same timing failure remains. Cache each nonzero metric
while polling (including QPS) and assert the cached values.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]