mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
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:
parent
801741ff81
commit
7b153d14ef
1 changed files with 6 additions and 6 deletions
|
@ -4029,7 +4029,7 @@ class TimerfdTests(unittest.TestCase):
|
||||||
t = time.perf_counter() - t
|
t = time.perf_counter() - t
|
||||||
|
|
||||||
total_time = initial_expiration + interval * (count - 1)
|
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
|
# wait 3.5 time of interval
|
||||||
time.sleep( (count+0.5) * interval)
|
time.sleep( (count+0.5) * interval)
|
||||||
|
@ -4083,7 +4083,7 @@ class TimerfdTests(unittest.TestCase):
|
||||||
t = time.perf_counter() - t
|
t = time.perf_counter() - t
|
||||||
|
|
||||||
total_time = initial_expiration + interval * (count - 1)
|
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):
|
def check_timerfd_poll(self, nanoseconds):
|
||||||
fd = self.timerfd_create(time.CLOCK_REALTIME, flags=os.TFD_NONBLOCK)
|
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)
|
total_time = initial_expiration_ns + interval_ns * (count - 1)
|
||||||
if nanoseconds:
|
if nanoseconds:
|
||||||
dt = time.perf_counter_ns() - t
|
dt = time.perf_counter_ns() - t
|
||||||
self.assertGreater(dt, total_time)
|
self.assertGreater(dt, total_time - self.CLOCK_RES_NS)
|
||||||
else:
|
else:
|
||||||
dt = time.perf_counter() - t
|
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)
|
selector.unregister(fd)
|
||||||
|
|
||||||
def test_timerfd_poll(self):
|
def test_timerfd_poll(self):
|
||||||
|
@ -4189,7 +4189,7 @@ class TimerfdTests(unittest.TestCase):
|
||||||
t = time.perf_counter_ns() - t
|
t = time.perf_counter_ns() - t
|
||||||
|
|
||||||
total_time_ns = initial_expiration_ns + interval_ns * (count - 1)
|
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
|
# wait 3.5 time of interval
|
||||||
time.sleep( (count+0.5) * interval_ns / one_sec_in_nsec)
|
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
|
t = time.perf_counter_ns() - t
|
||||||
|
|
||||||
total_time_ns = initial_expiration_ns + interval_ns * (count - 1)
|
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):
|
class OSErrorTests(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue