feat fast test
Some checks failed
ci/push/linux-aarch64-gcc/1 Pipeline failed
ci/pr/linux-aarch64-gcc/1 Pipeline failed
ci/push/linux-x64-gcc/2 Pipeline failed
ci/push/linux-aarch64-gcc/2 Pipeline failed
ci/pr/linux-x64-gcc/1 Pipeline failed
ci/push/linux-x64-gcc/1 Pipeline failed
ci/pr/linux-x64-gcc/2 Pipeline failed
ci/pr/linux-aarch64-gcc/2 Pipeline failed

This commit is contained in:
tqcq 2024-08-11 10:36:49 +08:00
parent 5d28389cac
commit ef009a4ae9

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();
}