feat/support_fiber #6

Merged
tqcq merged 52 commits from feat/support_fiber into master 2024-08-11 13:03:04 +08:00
Showing only changes of commit ef009a4ae9 - Show all commits

View File

@ -13,9 +13,8 @@ class CondVarTest : public ::testing::Test {
void SetUp() override {
m = new Mutex();
cv = new CondVar();
is_set = false;
is_timeout = false;
worker = nullptr;
ResetEnv();
}
void TearDown() override {
@ -25,6 +24,13 @@ class CondVarTest : public ::testing::Test {
}
delete worker;
}
delete m;
delete cv;
}
void ResetEnv() {
is_set = false;
is_timeout = false;
}
protected:
@ -62,12 +68,13 @@ TEST_F(CondVarTest, NotifyOne_Wait) {
TEST_F(CondVarTest, NotifyOne_WaitFor) {
// Wait
constexpr auto kWaitTimeoutMs = 100;
// constexpr auto kWaitTimeoutMs = 100;
constexpr auto kWaitTimeout = std::chrono::milliseconds(50);
auto WaitFor = [&] {
UniqueLock<Mutex> inner_locker(*m);
if (cv->WaitFor(inner_locker, std::chrono::milliseconds(kWaitTimeoutMs))) {
cv->NotifyOne();
if (cv->WaitFor(inner_locker, kWaitTimeout)) {
is_set = true;
cv->NotifyOne();
} else {
is_timeout = true;
}
@ -76,7 +83,7 @@ TEST_F(CondVarTest, NotifyOne_WaitFor) {
std::thread t1(WaitFor);
std::this_thread::sleep_for(std::chrono::milliseconds(kWaitTimeoutMs / 2));
std::this_thread::sleep_for(kWaitTimeout / 2);
ASSERT_FALSE(is_set);
{
@ -86,6 +93,7 @@ TEST_F(CondVarTest, NotifyOne_WaitFor) {
t1.join();
ASSERT_TRUE(is_set);
ASSERT_FALSE(is_timeout);
}
// timeout
@ -95,8 +103,7 @@ TEST_F(CondVarTest, NotifyOne_WaitFor) {
{
UniqueLock<Mutex> locker(*m);
ASSERT_FALSE(is_timeout);
std::this_thread::sleep_for(
std::chrono::milliseconds(kWaitTimeoutMs * 2));
std::this_thread::sleep_for(kWaitTimeout);
ASSERT_FALSE(is_timeout);
cv->NotifyOne();
}