gh-110697: Use CLOCK_RES in test_os.TimerfdTests (#111529)

More TimerfdTests tests tolerate a difference of 1 ms in measured
elapsed time.
This commit is contained in:
Victor Stinner 2023-10-30 23:47:59 +01:00 committed by GitHub
parent 801741ff81
commit 7b153d14ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 6 deletions

View File

@ -4029,7 +4029,7 @@ class TimerfdTests(unittest.TestCase):
t = time.perf_counter() - t
total_time = initial_expiration + interval * (count - 1)
self.assertGreater(t, total_time)
self.assertGreater(t, total_time - self.CLOCK_RES)
# wait 3.5 time of interval
time.sleep( (count+0.5) * interval)
@ -4083,7 +4083,7 @@ class TimerfdTests(unittest.TestCase):
t = time.perf_counter() - t
total_time = initial_expiration + interval * (count - 1)
self.assertGreater(t, total_time)
self.assertGreater(t, total_time - self.CLOCK_RES)
def check_timerfd_poll(self, nanoseconds):
fd = self.timerfd_create(time.CLOCK_REALTIME, flags=os.TFD_NONBLOCK)
@ -4129,10 +4129,10 @@ class TimerfdTests(unittest.TestCase):
total_time = initial_expiration_ns + interval_ns * (count - 1)
if nanoseconds:
dt = time.perf_counter_ns() - t
self.assertGreater(dt, total_time)
self.assertGreater(dt, total_time - self.CLOCK_RES_NS)
else:
dt = time.perf_counter() - t
self.assertGreater(dt, total_time / sec_to_nsec)
self.assertGreater(dt, total_time / sec_to_nsec - self.CLOCK_RES)
selector.unregister(fd)
def test_timerfd_poll(self):
@ -4189,7 +4189,7 @@ class TimerfdTests(unittest.TestCase):
t = time.perf_counter_ns() - t
total_time_ns = initial_expiration_ns + interval_ns * (count - 1)
self.assertGreater(t, total_time_ns)
self.assertGreater(t, total_time_ns - self.CLOCK_RES_NS)
# wait 3.5 time of interval
time.sleep( (count+0.5) * interval_ns / one_sec_in_nsec)
@ -4248,7 +4248,7 @@ class TimerfdTests(unittest.TestCase):
t = time.perf_counter_ns() - t
total_time_ns = initial_expiration_ns + interval_ns * (count - 1)
self.assertGreater(t, total_time_ns)
self.assertGreater(t, total_time_ns - self.CLOCK_RES_NS)
class OSErrorTests(unittest.TestCase):
def setUp(self):