Copilot commented on code in PR #3554:
URL: https://github.com/apache/brpc/pull/3554#discussion_r4052705970


##########
test/bthread_butex_unittest.cpp:
##########
@@ -45,25 +45,36 @@ TEST(ButexTest, wait_on_already_timedout_butex) {
     ASSERT_EQ(ETIMEDOUT, errno);
 }
 
+struct JoinSleepArg {
+    bthread_t tid = 0;
+    uint64_t sleep_us = 0;
+    butil::atomic<bool> finished{false};
+};
+
 void* sleeper(void* arg) {
     bthread_usleep((uint64_t)arg);
     return nullptr;
 }
 
+void* join_sleeper(void* arg) {
+    JoinSleepArg* a = static_cast<JoinSleepArg*>(arg);
+    butil::Timer tm;
+    tm.start();
+    EXPECT_EQ(0, bthread_usleep(a->sleep_us));
+    tm.stop();
+    EXPECT_GE(tm.u_elapsed(), static_cast<int64_t>(a->sleep_us));

Review Comment:
   This lower-bound check is still susceptible to a boundary flake: normal 
`bthread_usleep` schedules an absolute deadline after converting it to integer 
microseconds, while `Timer::u_elapsed()` floors nanoseconds to microseconds. A 
valid 100000-us sleep can therefore be observed as 99999 us when the fractional 
microsecond is lost, causing this assertion to fail intermittently. Compare 
with the same clock or account for the one-microsecond quantization.



-- 
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]

Reply via email to