[ci] Deflakey gcs_heartbeat_test in windows. (#27275)

We need to check the time after acquiring the lock to make sure the correctness. Otherwise, it might wait for the lock and the heartbeat has been updated.
This commit is contained in:
Yi Cheng 2022-07-29 22:42:28 +00:00 committed by GitHub
parent 8bdeb30510
commit 4ef4ec8eed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -66,8 +66,11 @@ TEST_F(GcsHeartbeatManagerTest, TestBasicTimeout) {
auto start = absl::Now(); auto start = absl::Now();
AddNode(node_1); AddNode(node_1);
while (absl::Now() - start < absl::Seconds(1)) { while (true) {
absl::MutexLock lock(&mutex_); absl::MutexLock lock(&mutex_);
if (absl::Now() - start >= absl::Seconds(1)) {
break;
}
ASSERT_TRUE(dead_nodes.empty()); ASSERT_TRUE(dead_nodes.empty());
} }
@ -84,8 +87,11 @@ TEST_F(GcsHeartbeatManagerTest, TestBasicReport) {
auto start = absl::Now(); auto start = absl::Now();
AddNode(node_1); AddNode(node_1);
while (absl::Now() - start < absl::Seconds(3)) { while (true) {
absl::MutexLock lock(&mutex_); absl::MutexLock lock(&mutex_);
if (absl::Now() - start >= absl::Seconds(3)) {
break;
}
ASSERT_TRUE(dead_nodes.empty()); ASSERT_TRUE(dead_nodes.empty());
io_service.post( io_service.post(
[&]() { [&]() {
@ -116,8 +122,11 @@ TEST_F(GcsHeartbeatManagerTest, TestBasicRestart) {
heartbeat_manager->Initialize(init_data); heartbeat_manager->Initialize(init_data);
while (absl::Now() - start < absl::Seconds(3)) { while (true) {
absl::MutexLock lock(&mutex_); absl::MutexLock lock(&mutex_);
if (absl::Now() - start >= absl::Seconds(3)) {
break;
}
ASSERT_TRUE(dead_nodes.empty()); ASSERT_TRUE(dead_nodes.empty());
} }
@ -158,8 +167,11 @@ TEST_F(GcsHeartbeatManagerTest, TestBasicRestart2) {
std::this_thread::sleep_for(0.1s); std::this_thread::sleep_for(0.1s);
} }
while (absl::Now() - start < absl::Seconds(1)) { while (true) {
absl::MutexLock lock(&mutex_); absl::MutexLock lock(&mutex_);
if (absl::Now() - start >= absl::Seconds(1)) {
break;
}
ASSERT_TRUE(dead_nodes.empty()); ASSERT_TRUE(dead_nodes.empty());
} }