wasphin commented on code in PR #3545:
URL: https://github.com/apache/brpc/pull/3545#discussion_r4053411507
##########
test/bthread_unittest.cpp:
##########
@@ -501,21 +501,32 @@ TEST_F(BthreadTest, start_latency_when_high_idle) {
}
void* sleep_for_awhile_with_sleep(void* arg) {
- bthread_usleep((intptr_t)arg);
+ int rc = bthread_usleep((intptr_t)arg);
+ int error = errno;
+ EXPECT_EQ(-1, rc);
+ EXPECT_EQ(ESTOP, error);
return nullptr;
}
TEST_F(BthreadTest, stop_sleep) {
bthread_t th;
ASSERT_EQ(0, bthread_start_urgent(
- &th, nullptr, sleep_for_awhile_with_sleep, (void*)1000000L));
- butil::Timer tm;
- tm.start();
- bthread_usleep(10000);
+ &th, nullptr, sleep_for_awhile_with_sleep,
(void*)60000000L));
+ auto* meta = bthread::TaskGroup::address_meta(th);
+ int64_t deadline = butil::cpuwide_time_us() + 5000000L;
+ bool sleeping = false;
+ do {
+ pthread_spin_lock(&meta->version_lock);
+ sleeping = (meta->current_sleep != 0);
+ pthread_spin_unlock(&meta->version_lock);
+ if (sleeping) {
+ break;
+ }
+ bthread_usleep(1000);
+ } while (butil::cpuwide_time_us() < deadline);
+ ASSERT_TRUE(sleeping);
Review Comment:
Please use a non-fatal assertion here and always execute `bthread_stop` and
`bthread_join`. If registration is not observed before the deadline, this
`ASSERT_TRUE` returns immediately and leaves the 60-second sleeper running.
Stopping is still safe before `current_sleep` is published because bthread
interruption is persistent and `_add_sleep_event` handles an
already-interrupted task.
--
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]