feat add timeout
Some checks failed
ci/pr/linux-aarch64-gcc/1 Pipeline failed
ci/push/linux-aarch64-gcc/1 Pipeline was successful
ci/push/linux-x64-gcc/2 Pipeline failed
ci/push/linux-aarch64-gcc/2 Pipeline failed
ci/pr/linux-x64-gcc/1 Pipeline was successful
ci/pr/linux-aarch64-gcc/2 Pipeline failed
ci/push/linux-x64-gcc/1 Pipeline was successful
ci/pr/linux-x64-gcc/2 Pipeline failed
Some checks failed
ci/pr/linux-aarch64-gcc/1 Pipeline failed
ci/push/linux-aarch64-gcc/1 Pipeline was successful
ci/push/linux-x64-gcc/2 Pipeline failed
ci/push/linux-aarch64-gcc/2 Pipeline failed
ci/pr/linux-x64-gcc/1 Pipeline was successful
ci/pr/linux-aarch64-gcc/2 Pipeline failed
ci/push/linux-x64-gcc/1 Pipeline was successful
ci/pr/linux-x64-gcc/2 Pipeline failed
This commit is contained in:
parent
ef009a4ae9
commit
7b13e5584a
@ -36,8 +36,8 @@ class CondVarTest : public ::testing::Test {
|
|||||||
protected:
|
protected:
|
||||||
Mutex *m;
|
Mutex *m;
|
||||||
CondVar *cv;
|
CondVar *cv;
|
||||||
volatile bool is_set;
|
bool is_set;
|
||||||
volatile bool is_timeout;
|
bool is_timeout;
|
||||||
std::thread *worker;
|
std::thread *worker;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -69,6 +69,7 @@ TEST_F(CondVarTest, NotifyOne_Wait) {
|
|||||||
TEST_F(CondVarTest, NotifyOne_WaitFor) {
|
TEST_F(CondVarTest, NotifyOne_WaitFor) {
|
||||||
// Wait
|
// Wait
|
||||||
// constexpr auto kWaitTimeoutMs = 100;
|
// constexpr auto kWaitTimeoutMs = 100;
|
||||||
|
auto start = ReadSteadyClock();
|
||||||
constexpr auto kWaitTimeout = std::chrono::milliseconds(50);
|
constexpr auto kWaitTimeout = std::chrono::milliseconds(50);
|
||||||
auto WaitFor = [&] {
|
auto WaitFor = [&] {
|
||||||
UniqueLock<Mutex> inner_locker(*m);
|
UniqueLock<Mutex> inner_locker(*m);
|
||||||
@ -91,9 +92,16 @@ TEST_F(CondVarTest, NotifyOne_WaitFor) {
|
|||||||
cv->NotifyOne();
|
cv->NotifyOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto now = ReadSteadyClock();
|
||||||
t1.join();
|
t1.join();
|
||||||
ASSERT_TRUE(is_set);
|
if (now - start > kWaitTimeout) {
|
||||||
|
// timeout
|
||||||
|
ASSERT_TRUE(is_timeout);
|
||||||
|
ASSERT_FALSE(is_set);
|
||||||
|
} else {
|
||||||
ASSERT_FALSE(is_timeout);
|
ASSERT_FALSE(is_timeout);
|
||||||
|
ASSERT_TRUE(is_set);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// timeout
|
// timeout
|
||||||
|
Loading…
Reference in New Issue
Block a user