about summary refs log tree commit diff
path: root/absl/synchronization
diff options
context:
space:
mode:
Diffstat (limited to 'absl/synchronization')
-rw-r--r--absl/synchronization/internal/per_thread_sem_test.cc7
-rw-r--r--absl/synchronization/notification_test.cc9
2 files changed, 11 insertions, 5 deletions
diff --git a/absl/synchronization/internal/per_thread_sem_test.cc b/absl/synchronization/internal/per_thread_sem_test.cc
index 2b52ea76ab0e..c29d8403df43 100644
--- a/absl/synchronization/internal/per_thread_sem_test.cc
+++ b/absl/synchronization/internal/per_thread_sem_test.cc
@@ -153,12 +153,15 @@ TEST_F(PerThreadSemTest, WithTimeout) {
 
 TEST_F(PerThreadSemTest, Timeouts) {
   absl::Time timeout = absl::Now() + absl::Milliseconds(50);
+  // Allow for a slight early return, to account for quality of implementation
+  // issues on various platforms.
+  const absl::Duration slop = absl::Microseconds(200);
   EXPECT_FALSE(Wait(timeout));
-  EXPECT_LE(timeout, absl::Now());
+  EXPECT_LE(timeout, absl::Now() + slop);
 
   absl::Time negative_timeout = absl::UnixEpoch() - absl::Milliseconds(100);
   EXPECT_FALSE(Wait(negative_timeout));
-  EXPECT_LE(negative_timeout, absl::Now());  // trivially true :)
+  EXPECT_LE(negative_timeout, absl::Now() + slop);  // trivially true :)
 
   Post(GetOrCreateCurrentThreadIdentity());
   // The wait here has an expired timeout, but we have a wake to consume,
diff --git a/absl/synchronization/notification_test.cc b/absl/synchronization/notification_test.cc
index 9b3b6a5a9e84..d8708d551a15 100644
--- a/absl/synchronization/notification_test.cc
+++ b/absl/synchronization/notification_test.cc
@@ -71,10 +71,13 @@ static void BasicTests(bool notify_before_waiting, Notification* notification) {
       notification->WaitForNotificationWithTimeout(absl::Milliseconds(0)));
   EXPECT_FALSE(notification->WaitForNotificationWithDeadline(absl::Now()));
 
+  const absl::Duration delay = absl::Milliseconds(50);
+  // Allow for a slight early return, to account for quality of implementation
+  // issues on various platforms.
+  const absl::Duration slop = absl::Microseconds(200);
   absl::Time start = absl::Now();
-  EXPECT_FALSE(
-      notification->WaitForNotificationWithTimeout(absl::Milliseconds(50)));
-  EXPECT_LE(start + absl::Milliseconds(50), absl::Now());
+  EXPECT_FALSE(notification->WaitForNotificationWithTimeout(delay));
+  EXPECT_LE(start + delay, absl::Now() + slop);
 
   ThreadSafeCounter ready_counter;
   ThreadSafeCounter done_counter;