mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
Backport fixes on test_eintr
* Issue #25234: Skip test_eintr.test_open() under OS X to avoid hanging * Issue #25868: Try to make test_eintr.test_sigwaitinfo() more reliable especially on slow buildbots. Use a pipe to synchronize the parent and the child processes.
This commit is contained in:
parent
ad13edb6fd
commit
8f475effbc
1 changed files with 17 additions and 5 deletions
|
|
@ -334,10 +334,12 @@ class SocketEINTRTest(EINTRBaseTest):
|
||||||
self._test_open("fp = open(path, 'r')\nfp.close()",
|
self._test_open("fp = open(path, 'r')\nfp.close()",
|
||||||
self.python_open)
|
self.python_open)
|
||||||
|
|
||||||
|
@unittest.skipIf(sys.platform == 'darwin', "hangs under OS X; see issue #25234")
|
||||||
def os_open(self, path):
|
def os_open(self, path):
|
||||||
fd = os.open(path, os.O_WRONLY)
|
fd = os.open(path, os.O_WRONLY)
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
|
|
||||||
|
@unittest.skipIf(sys.platform == "darwin", "hangs under OS X; see issue #25234")
|
||||||
def test_os_open(self):
|
def test_os_open(self):
|
||||||
self._test_open("fd = os.open(path, os.O_RDONLY)\nos.close(fd)",
|
self._test_open("fd = os.open(path, os.O_RDONLY)\nos.close(fd)",
|
||||||
self.os_open)
|
self.os_open)
|
||||||
|
|
@ -370,10 +372,10 @@ class SignalEINTRTest(EINTRBaseTest):
|
||||||
@unittest.skipUnless(hasattr(signal, 'sigwaitinfo'),
|
@unittest.skipUnless(hasattr(signal, 'sigwaitinfo'),
|
||||||
'need signal.sigwaitinfo()')
|
'need signal.sigwaitinfo()')
|
||||||
def test_sigwaitinfo(self):
|
def test_sigwaitinfo(self):
|
||||||
# Issue #25277: The sleep is a weak synchronization between the parent
|
# Issue #25277, #25868: give a few miliseconds to the parent process
|
||||||
# and the child process. If the sleep is too low, the test hangs on
|
# between os.write() and signal.sigwaitinfo() to works around a race
|
||||||
# slow or highly loaded systems.
|
# condition
|
||||||
self.sleep_time = 2.0
|
self.sleep_time = 0.100
|
||||||
|
|
||||||
signum = signal.SIGUSR1
|
signum = signal.SIGUSR1
|
||||||
pid = os.getpid()
|
pid = os.getpid()
|
||||||
|
|
@ -381,18 +383,28 @@ class SignalEINTRTest(EINTRBaseTest):
|
||||||
old_handler = signal.signal(signum, lambda *args: None)
|
old_handler = signal.signal(signum, lambda *args: None)
|
||||||
self.addCleanup(signal.signal, signum, old_handler)
|
self.addCleanup(signal.signal, signum, old_handler)
|
||||||
|
|
||||||
|
rpipe, wpipe = os.pipe()
|
||||||
|
|
||||||
code = '\n'.join((
|
code = '\n'.join((
|
||||||
'import os, time',
|
'import os, time',
|
||||||
'pid = %s' % os.getpid(),
|
'pid = %s' % os.getpid(),
|
||||||
'signum = %s' % int(signum),
|
'signum = %s' % int(signum),
|
||||||
'sleep_time = %r' % self.sleep_time,
|
'sleep_time = %r' % self.sleep_time,
|
||||||
|
'rpipe = %r' % rpipe,
|
||||||
|
'os.read(rpipe, 1)',
|
||||||
|
'os.close(rpipe)',
|
||||||
'time.sleep(sleep_time)',
|
'time.sleep(sleep_time)',
|
||||||
'os.kill(pid, signum)',
|
'os.kill(pid, signum)',
|
||||||
))
|
))
|
||||||
|
|
||||||
t0 = time.monotonic()
|
t0 = time.monotonic()
|
||||||
proc = self.subprocess(code)
|
proc = self.subprocess(code, pass_fds=(rpipe,))
|
||||||
|
os.close(rpipe)
|
||||||
with kill_on_error(proc):
|
with kill_on_error(proc):
|
||||||
|
# sync child-parent
|
||||||
|
os.write(wpipe, b'x')
|
||||||
|
os.close(wpipe)
|
||||||
|
|
||||||
# parent
|
# parent
|
||||||
signal.sigwaitinfo([signum])
|
signal.sigwaitinfo([signum])
|
||||||
dt = time.monotonic() - t0
|
dt = time.monotonic() - t0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue