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


##########
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:
   Fixed by allowing the one-microsecond quantization introduced when 
Timer::u_elapsed() floors nanoseconds. The join test still rejects an early 
sleep beyond that rounding boundary, and it passes 20 repeated runs.



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