Commit 1d4be0a6 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-33532: Fix test_multiprocessing_forkserver.test_ignore() (GH-7323)

Use also support.SOCK_MAX_SIZE, not only support.PIPE_MAX_SIZE, to
get the size for a blocking send into a multiprocessing pipe.

Replace also test_support with support.
parent 3604b239
...@@ -16,16 +16,16 @@ import logging ...@@ -16,16 +16,16 @@ import logging
import errno import errno
import weakref import weakref
import test.script_helper import test.script_helper
from test import test_support from test import support
from StringIO import StringIO from StringIO import StringIO
_multiprocessing = test_support.import_module('_multiprocessing') _multiprocessing = support.import_module('_multiprocessing')
# import threading after _multiprocessing to raise a more relevant error # import threading after _multiprocessing to raise a more relevant error
# message: "No module named _multiprocessing". _multiprocessing is not compiled # message: "No module named _multiprocessing". _multiprocessing is not compiled
# without thread support. # without thread support.
import threading import threading
# Work around broken sem_open implementations # Work around broken sem_open implementations
test_support.import_module('multiprocessing.synchronize') support.import_module('multiprocessing.synchronize')
import multiprocessing.dummy import multiprocessing.dummy
import multiprocessing.connection import multiprocessing.connection
...@@ -341,8 +341,8 @@ class _TestProcess(BaseTestCase): ...@@ -341,8 +341,8 @@ class _TestProcess(BaseTestCase):
if self.TYPE == 'threads': if self.TYPE == 'threads':
self.skipTest('test not appropriate for {}'.format(self.TYPE)) self.skipTest('test not appropriate for {}'.format(self.TYPE))
testfn = test_support.TESTFN testfn = support.TESTFN
self.addCleanup(test_support.unlink, testfn) self.addCleanup(support.unlink, testfn)
for reason, code in (([1, 2, 3], 1), ('ignore this', 1)): for reason, code in (([1, 2, 3], 1), ('ignore this', 1)):
p = self.Process(target=self._test_sys_exit, args=(reason, testfn)) p = self.Process(target=self._test_sys_exit, args=(reason, testfn))
...@@ -640,7 +640,7 @@ class _TestQueue(BaseTestCase): ...@@ -640,7 +640,7 @@ class _TestQueue(BaseTestCase):
p.join() p.join()
def test_no_import_lock_contention(self): def test_no_import_lock_contention(self):
with test_support.temp_cwd(): with support.temp_cwd():
module_name = 'imported_by_an_imported_module' module_name = 'imported_by_an_imported_module'
with open(module_name + '.py', 'w') as f: with open(module_name + '.py', 'w') as f:
f.write("""if 1: f.write("""if 1:
...@@ -652,7 +652,7 @@ class _TestQueue(BaseTestCase): ...@@ -652,7 +652,7 @@ class _TestQueue(BaseTestCase):
q.close() q.close()
""") """)
with test_support.DirsOnSysPath(os.getcwd()): with support.DirsOnSysPath(os.getcwd()):
try: try:
__import__(module_name) __import__(module_name)
except Queue.Empty: except Queue.Empty:
...@@ -1517,10 +1517,10 @@ class _TestRemoteManager(BaseTestCase): ...@@ -1517,10 +1517,10 @@ class _TestRemoteManager(BaseTestCase):
#'hall\xc3\xa5 v\xc3\xa4rlden'] # UTF-8 #'hall\xc3\xa5 v\xc3\xa4rlden'] # UTF-8
] ]
result = values[:] result = values[:]
if test_support.have_unicode: if support.have_unicode:
#result[-1] = u'hall\xe5 v\xe4rlden' #result[-1] = u'hall\xe5 v\xe4rlden'
uvalue = test_support.u(r'\u043f\u0440\u0438\u0432\u0456\u0442 ' uvalue = support.u(r'\u043f\u0440\u0438\u0432\u0456\u0442 '
r'\u0441\u0432\u0456\u0442') r'\u0441\u0432\u0456\u0442')
values.append(uvalue) values.append(uvalue)
result.append(uvalue) result.append(uvalue)
...@@ -1538,7 +1538,7 @@ class _TestRemoteManager(BaseTestCase): ...@@ -1538,7 +1538,7 @@ class _TestRemoteManager(BaseTestCase):
authkey = os.urandom(32) authkey = os.urandom(32)
manager = QueueManager( manager = QueueManager(
address=(test.test_support.HOST, 0), authkey=authkey, serializer=SERIALIZER address=(test.support.HOST, 0), authkey=authkey, serializer=SERIALIZER
) )
manager.start() manager.start()
...@@ -1575,7 +1575,7 @@ class _TestManagerRestart(BaseTestCase): ...@@ -1575,7 +1575,7 @@ class _TestManagerRestart(BaseTestCase):
def test_rapid_restart(self): def test_rapid_restart(self):
authkey = os.urandom(32) authkey = os.urandom(32)
manager = QueueManager( manager = QueueManager(
address=(test.test_support.HOST, 0), authkey=authkey, serializer=SERIALIZER) address=(test.support.HOST, 0), authkey=authkey, serializer=SERIALIZER)
srvr = manager.get_server() srvr = manager.get_server()
addr = srvr.address addr = srvr.address
# Close the connection.Listener socket which gets opened as a part # Close the connection.Listener socket which gets opened as a part
...@@ -1786,13 +1786,13 @@ class _TestConnection(BaseTestCase): ...@@ -1786,13 +1786,13 @@ class _TestConnection(BaseTestCase):
p = self.Process(target=self._writefd, args=(child_conn, b"foo")) p = self.Process(target=self._writefd, args=(child_conn, b"foo"))
p.daemon = True p.daemon = True
p.start() p.start()
with open(test_support.TESTFN, "wb") as f: with open(support.TESTFN, "wb") as f:
fd = f.fileno() fd = f.fileno()
if msvcrt: if msvcrt:
fd = msvcrt.get_osfhandle(fd) fd = msvcrt.get_osfhandle(fd)
reduction.send_handle(conn, fd, p.pid) reduction.send_handle(conn, fd, p.pid)
p.join() p.join()
with open(test_support.TESTFN, "rb") as f: with open(support.TESTFN, "rb") as f:
self.assertEqual(f.read(), b"foo") self.assertEqual(f.read(), b"foo")
@unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction") @unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
...@@ -1811,7 +1811,7 @@ class _TestConnection(BaseTestCase): ...@@ -1811,7 +1811,7 @@ class _TestConnection(BaseTestCase):
p = self.Process(target=self._writefd, args=(child_conn, b"bar", True)) p = self.Process(target=self._writefd, args=(child_conn, b"bar", True))
p.daemon = True p.daemon = True
p.start() p.start()
with open(test_support.TESTFN, "wb") as f: with open(support.TESTFN, "wb") as f:
fd = f.fileno() fd = f.fileno()
for newfd in range(256, MAXFD): for newfd in range(256, MAXFD):
if not self._is_fd_assigned(newfd): if not self._is_fd_assigned(newfd):
...@@ -1824,7 +1824,7 @@ class _TestConnection(BaseTestCase): ...@@ -1824,7 +1824,7 @@ class _TestConnection(BaseTestCase):
finally: finally:
os.close(newfd) os.close(newfd)
p.join() p.join()
with open(test_support.TESTFN, "rb") as f: with open(support.TESTFN, "rb") as f:
self.assertEqual(f.read(), b"bar") self.assertEqual(f.read(), b"bar")
@classmethod @classmethod
...@@ -2207,7 +2207,7 @@ class _TestFinalize(BaseTestCase): ...@@ -2207,7 +2207,7 @@ class _TestFinalize(BaseTestCase):
gc.set_threshold(5, 5, 5) gc.set_threshold(5, 5, 5)
threads = [threading.Thread(target=run_finalizers), threads = [threading.Thread(target=run_finalizers),
threading.Thread(target=make_finalizers)] threading.Thread(target=make_finalizers)]
with test_support.start_threads(threads): with support.start_threads(threads):
time.sleep(4.0) # Wait a bit to trigger race condition time.sleep(4.0) # Wait a bit to trigger race condition
finish = True finish = True
if exc: if exc:
...@@ -2635,7 +2635,7 @@ class TestFlags(unittest.TestCase): ...@@ -2635,7 +2635,7 @@ class TestFlags(unittest.TestCase):
flags = (tuple(sys.flags), grandchild_flags) flags = (tuple(sys.flags), grandchild_flags)
print(json.dumps(flags)) print(json.dumps(flags))
@test_support.requires_unicode # XXX json needs unicode support @support.requires_unicode # XXX json needs unicode support
def test_flags(self): def test_flags(self):
import json, subprocess import json, subprocess
# start child process using unusual flags # start child process using unusual flags
...@@ -2681,6 +2681,9 @@ class TestForkAwareThreadLock(unittest.TestCase): ...@@ -2681,6 +2681,9 @@ class TestForkAwareThreadLock(unittest.TestCase):
class TestIgnoreEINTR(unittest.TestCase): class TestIgnoreEINTR(unittest.TestCase):
# Sending CONN_MAX_SIZE bytes into a multiprocessing pipe must block
CONN_MAX_SIZE = max(support.PIPE_MAX_SIZE, support.SOCK_MAX_SIZE)
@classmethod @classmethod
def _test_ignore(cls, conn): def _test_ignore(cls, conn):
def handler(signum, frame): def handler(signum, frame):
...@@ -2689,7 +2692,7 @@ class TestIgnoreEINTR(unittest.TestCase): ...@@ -2689,7 +2692,7 @@ class TestIgnoreEINTR(unittest.TestCase):
conn.send('ready') conn.send('ready')
x = conn.recv() x = conn.recv()
conn.send(x) conn.send(x)
conn.send_bytes(b'x' * test_support.PIPE_MAX_SIZE) conn.send_bytes(b'x' * cls.CONN_MAX_SIZE)
@unittest.skipUnless(hasattr(signal, 'SIGUSR1'), 'requires SIGUSR1') @unittest.skipUnless(hasattr(signal, 'SIGUSR1'), 'requires SIGUSR1')
def test_ignore(self): def test_ignore(self):
...@@ -2708,8 +2711,7 @@ class TestIgnoreEINTR(unittest.TestCase): ...@@ -2708,8 +2711,7 @@ class TestIgnoreEINTR(unittest.TestCase):
self.assertEqual(conn.recv(), 1234) self.assertEqual(conn.recv(), 1234)
time.sleep(0.1) time.sleep(0.1)
os.kill(p.pid, signal.SIGUSR1) os.kill(p.pid, signal.SIGUSR1)
self.assertEqual(conn.recv_bytes(), self.assertEqual(conn.recv_bytes(), b'x' * self.CONN_MAX_SIZE)
b'x' * test_support.PIPE_MAX_SIZE)
time.sleep(0.1) time.sleep(0.1)
p.join() p.join()
finally: finally:
...@@ -2766,7 +2768,7 @@ def test_main(run=None): ...@@ -2766,7 +2768,7 @@ def test_main(run=None):
check_enough_semaphores() check_enough_semaphores()
if run is None: if run is None:
from test.test_support import run_unittest as run from test.support import run_unittest as run
util.get_temp_dir() # creates temp directory for use by all processes util.get_temp_dir() # creates temp directory for use by all processes
...@@ -2791,7 +2793,7 @@ def test_main(run=None): ...@@ -2791,7 +2793,7 @@ def test_main(run=None):
# module during these tests is at least platform dependent and possibly # module during these tests is at least platform dependent and possibly
# non-deterministic on any given platform. So we don't mind if the listed # non-deterministic on any given platform. So we don't mind if the listed
# warnings aren't actually raised. # warnings aren't actually raised.
with test_support.check_py3k_warnings( with support.check_py3k_warnings(
(".+__(get|set)slice__ has been removed", DeprecationWarning), (".+__(get|set)slice__ has been removed", DeprecationWarning),
(r"sys.exc_clear\(\) not supported", DeprecationWarning), (r"sys.exc_clear\(\) not supported", DeprecationWarning),
quiet=True): quiet=True):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment