mirror of https://github.com/python/cpython
gh-109592: test_eintr tolerates 20 ms when comparing timings (#110102)
This commit is contained in:
parent
86e76ab8af
commit
9c73a9acec
|
@ -25,6 +25,12 @@ from test import support
|
||||||
from test.support import os_helper
|
from test.support import os_helper
|
||||||
from test.support import socket_helper
|
from test.support import socket_helper
|
||||||
|
|
||||||
|
|
||||||
|
# gh-109592: Tolerate a difference of 20 ms when comparing timings
|
||||||
|
# (clock resolution)
|
||||||
|
CLOCK_RES = 0.020
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def kill_on_error(proc):
|
def kill_on_error(proc):
|
||||||
"""Context manager killing the subprocess if a Python exception is raised."""
|
"""Context manager killing the subprocess if a Python exception is raised."""
|
||||||
|
@ -75,6 +81,9 @@ class EINTRBaseTest(unittest.TestCase):
|
||||||
cmd_args = (sys.executable, '-c') + args
|
cmd_args = (sys.executable, '-c') + args
|
||||||
return subprocess.Popen(cmd_args, **kw)
|
return subprocess.Popen(cmd_args, **kw)
|
||||||
|
|
||||||
|
def check_elapsed_time(self, elapsed):
|
||||||
|
self.assertGreaterEqual(elapsed, self.sleep_time - CLOCK_RES)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(signal, "setitimer"), "requires setitimer()")
|
@unittest.skipUnless(hasattr(signal, "setitimer"), "requires setitimer()")
|
||||||
class OSEINTRTest(EINTRBaseTest):
|
class OSEINTRTest(EINTRBaseTest):
|
||||||
|
@ -373,7 +382,7 @@ class TimeEINTRTest(EINTRBaseTest):
|
||||||
time.sleep(self.sleep_time)
|
time.sleep(self.sleep_time)
|
||||||
self.stop_alarm()
|
self.stop_alarm()
|
||||||
dt = time.monotonic() - t0
|
dt = time.monotonic() - t0
|
||||||
self.assertGreaterEqual(dt, self.sleep_time)
|
self.check_elapsed_time(dt)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(signal, "setitimer"), "requires setitimer()")
|
@unittest.skipUnless(hasattr(signal, "setitimer"), "requires setitimer()")
|
||||||
|
@ -435,7 +444,7 @@ class SelectEINTRTest(EINTRBaseTest):
|
||||||
select.select([], [], [], self.sleep_time)
|
select.select([], [], [], self.sleep_time)
|
||||||
dt = time.monotonic() - t0
|
dt = time.monotonic() - t0
|
||||||
self.stop_alarm()
|
self.stop_alarm()
|
||||||
self.assertGreaterEqual(dt, self.sleep_time)
|
self.check_elapsed_time(dt)
|
||||||
|
|
||||||
@unittest.skipIf(sys.platform == "darwin",
|
@unittest.skipIf(sys.platform == "darwin",
|
||||||
"poll may fail on macOS; see issue #28087")
|
"poll may fail on macOS; see issue #28087")
|
||||||
|
@ -447,7 +456,7 @@ class SelectEINTRTest(EINTRBaseTest):
|
||||||
poller.poll(self.sleep_time * 1e3)
|
poller.poll(self.sleep_time * 1e3)
|
||||||
dt = time.monotonic() - t0
|
dt = time.monotonic() - t0
|
||||||
self.stop_alarm()
|
self.stop_alarm()
|
||||||
self.assertGreaterEqual(dt, self.sleep_time)
|
self.check_elapsed_time(dt)
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(select, 'epoll'), 'need select.epoll')
|
@unittest.skipUnless(hasattr(select, 'epoll'), 'need select.epoll')
|
||||||
def test_epoll(self):
|
def test_epoll(self):
|
||||||
|
@ -458,7 +467,7 @@ class SelectEINTRTest(EINTRBaseTest):
|
||||||
poller.poll(self.sleep_time)
|
poller.poll(self.sleep_time)
|
||||||
dt = time.monotonic() - t0
|
dt = time.monotonic() - t0
|
||||||
self.stop_alarm()
|
self.stop_alarm()
|
||||||
self.assertGreaterEqual(dt, self.sleep_time)
|
self.check_elapsed_time(dt)
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(select, 'kqueue'), 'need select.kqueue')
|
@unittest.skipUnless(hasattr(select, 'kqueue'), 'need select.kqueue')
|
||||||
def test_kqueue(self):
|
def test_kqueue(self):
|
||||||
|
@ -469,7 +478,7 @@ class SelectEINTRTest(EINTRBaseTest):
|
||||||
kqueue.control(None, 1, self.sleep_time)
|
kqueue.control(None, 1, self.sleep_time)
|
||||||
dt = time.monotonic() - t0
|
dt = time.monotonic() - t0
|
||||||
self.stop_alarm()
|
self.stop_alarm()
|
||||||
self.assertGreaterEqual(dt, self.sleep_time)
|
self.check_elapsed_time(dt)
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(select, 'devpoll'), 'need select.devpoll')
|
@unittest.skipUnless(hasattr(select, 'devpoll'), 'need select.devpoll')
|
||||||
def test_devpoll(self):
|
def test_devpoll(self):
|
||||||
|
@ -480,7 +489,7 @@ class SelectEINTRTest(EINTRBaseTest):
|
||||||
poller.poll(self.sleep_time * 1e3)
|
poller.poll(self.sleep_time * 1e3)
|
||||||
dt = time.monotonic() - t0
|
dt = time.monotonic() - t0
|
||||||
self.stop_alarm()
|
self.stop_alarm()
|
||||||
self.assertGreaterEqual(dt, self.sleep_time)
|
self.check_elapsed_time(dt)
|
||||||
|
|
||||||
|
|
||||||
class FNTLEINTRTest(EINTRBaseTest):
|
class FNTLEINTRTest(EINTRBaseTest):
|
||||||
|
@ -512,8 +521,8 @@ class FNTLEINTRTest(EINTRBaseTest):
|
||||||
# potential context switch delay
|
# potential context switch delay
|
||||||
lock_func(f, fcntl.LOCK_EX)
|
lock_func(f, fcntl.LOCK_EX)
|
||||||
dt = time.monotonic() - start_time
|
dt = time.monotonic() - start_time
|
||||||
self.assertGreaterEqual(dt, self.sleep_time)
|
|
||||||
self.stop_alarm()
|
self.stop_alarm()
|
||||||
|
self.check_elapsed_time(dt)
|
||||||
proc.wait()
|
proc.wait()
|
||||||
|
|
||||||
# Issue 35633: See https://bugs.python.org/issue35633#msg333662
|
# Issue 35633: See https://bugs.python.org/issue35633#msg333662
|
||||||
|
|
Loading…
Reference in New Issue