diff options
author | Evan Brown <ezb@google.com> | 2023-04-20 11:50:15 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-04-20 11:51:02 -0700 |
commit | 9686b7be4416746a7187a1979f34d32b925a485b (patch) | |
tree | a5af1235d3d1c9cd4b4a48650cc7e83c5d0251f9 /absl/synchronization/internal | |
parent | bc65499db4413658779cf40f1fb5373bb92b50d8 (diff) |
Fix flaky test failures.
PiperOrigin-RevId: 525808747
Change-Id: I01aeef6b8558673bf1fc38a948dcecf00300b641
Diffstat (limited to 'absl/synchronization/internal')
-rw-r--r-- | absl/synchronization/internal/waiter_test.cc | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/absl/synchronization/internal/waiter_test.cc b/absl/synchronization/internal/waiter_test.cc index 9a933940..992db29b 100644 --- a/absl/synchronization/internal/waiter_test.cc +++ b/absl/synchronization/internal/waiter_test.cc @@ -72,7 +72,7 @@ class WaiterTest : public ::testing::Test { TYPED_TEST_SUITE_P(WaiterTest); -constexpr absl::Duration slop = absl::Milliseconds(10); +absl::Duration WithTolerance(absl::Duration d) { return d * 0.95; } TYPED_TEST_P(WaiterTest, WaitNoTimeout) { absl::synchronization_internal::ThreadPool tp(1); @@ -90,7 +90,7 @@ TYPED_TEST_P(WaiterTest, WaitNoTimeout) { EXPECT_TRUE( waiter.Wait(absl::synchronization_internal::KernelTimeout::Never())); absl::Duration waited = absl::Now() - start; - EXPECT_GE(waited, absl::Seconds(2) - slop); + EXPECT_GE(waited, WithTolerance(absl::Seconds(2))); } TYPED_TEST_P(WaiterTest, WaitDurationWoken) { @@ -107,7 +107,7 @@ TYPED_TEST_P(WaiterTest, WaitDurationWoken) { EXPECT_TRUE(waiter.Wait( absl::synchronization_internal::KernelTimeout(absl::Seconds(10)))); absl::Duration waited = absl::Now() - start; - EXPECT_GE(waited, absl::Milliseconds(500) - slop); + EXPECT_GE(waited, WithTolerance(absl::Milliseconds(500))); EXPECT_LT(waited, absl::Seconds(2)); } @@ -125,7 +125,7 @@ TYPED_TEST_P(WaiterTest, WaitTimeWoken) { EXPECT_TRUE(waiter.Wait(absl::synchronization_internal::KernelTimeout( start + absl::Seconds(10)))); absl::Duration waited = absl::Now() - start; - EXPECT_GE(waited, absl::Milliseconds(500) - slop); + EXPECT_GE(waited, WithTolerance(absl::Milliseconds(500))); EXPECT_LT(waited, absl::Seconds(2)); } @@ -135,7 +135,7 @@ TYPED_TEST_P(WaiterTest, WaitDurationReached) { EXPECT_FALSE(waiter.Wait( absl::synchronization_internal::KernelTimeout(absl::Milliseconds(500)))); absl::Duration waited = absl::Now() - start; - EXPECT_GE(waited, absl::Milliseconds(500) - slop); + EXPECT_GE(waited, WithTolerance(absl::Milliseconds(500))); EXPECT_LT(waited, absl::Seconds(1)); } @@ -145,7 +145,7 @@ TYPED_TEST_P(WaiterTest, WaitTimeReached) { EXPECT_FALSE(waiter.Wait(absl::synchronization_internal::KernelTimeout( start + absl::Milliseconds(500)))); absl::Duration waited = absl::Now() - start; - EXPECT_GE(waited, absl::Milliseconds(500) - slop); + EXPECT_GE(waited, WithTolerance(absl::Milliseconds(500))); EXPECT_LT(waited, absl::Seconds(1)); } |