bpo-33532: Fix test_multiprocessing_forkserver.test_ignore() (GH-7322) · python/cpython@64e538b
@@ -20,14 +20,14 @@
2020import struct
2121import operator
2222import weakref
23-import test.support
23+from test import support
2424import test.support.script_helper
252526262727# Skip tests if _multiprocessing wasn't built.
28-_multiprocessing = test.support.import_module('_multiprocessing')
28+_multiprocessing = support.import_module('_multiprocessing')
2929# Skip tests if sem_open implementation is broken.
30-test.support.import_module('multiprocessing.synchronize')
30+support.import_module('multiprocessing.synchronize')
3131# import threading after _multiprocessing to raise a more relevant error
3232# message: "No module named _multiprocessing". _multiprocessing is not compiled
3333# without thread support.
@@ -567,8 +567,8 @@ def test_stderr_flush(self):
567567if self.TYPE == "threads":
568568self.skipTest('test not appropriate for {}'.format(self.TYPE))
569569570-testfn = test.support.TESTFN
571-self.addCleanup(test.support.unlink, testfn)
570+testfn = support.TESTFN
571+self.addCleanup(support.unlink, testfn)
572572proc = self.Process(target=self._test_stderr_flush, args=(testfn,))
573573proc.start()
574574proc.join()
@@ -597,8 +597,8 @@ def test_sys_exit(self):
597597if self.TYPE == 'threads':
598598self.skipTest('test not appropriate for {}'.format(self.TYPE))
599599600-testfn = test.support.TESTFN
601-self.addCleanup(test.support.unlink, testfn)
600+testfn = support.TESTFN
601+self.addCleanup(support.unlink, testfn)
602602603603for reason in (
604604 [1, 2, 3],
@@ -853,7 +853,7 @@ def test_task_done(self):
853853close_queue(queue)
854854855855def test_no_import_lock_contention(self):
856-with test.support.temp_cwd():
856+with support.temp_cwd():
857857module_name = 'imported_by_an_imported_module'
858858with open(module_name + '.py', 'w') as f:
859859f.write("""if 1:
@@ -866,7 +866,7 @@ def test_no_import_lock_contention(self):
866866 del q
867867 """)
868868869-with test.support.DirsOnSysPath(os.getcwd()):
869+with support.DirsOnSysPath(os.getcwd()):
870870try:
871871__import__(module_name)
872872except pyqueue.Empty:
@@ -891,7 +891,7 @@ def test_queue_feeder_donot_stop_onexc(self):
891891class NotSerializable(object):
892892def __reduce__(self):
893893raise AttributeError
894-with test.support.captured_stderr():
894+with support.captured_stderr():
895895q = self.Queue()
896896q.put(NotSerializable())
897897q.put(True)
@@ -2194,7 +2194,7 @@ def test_traceback(self):
21942194self.assertIs(type(cause), multiprocessing.pool.RemoteTraceback)
21952195self.assertIn('raise RuntimeError(123) # some comment', cause.tb)
219621962197-with test.support.captured_stderr() as f1:
2197+with support.captured_stderr() as f1:
21982198try:
21992199raise exc
22002200except RuntimeError:
@@ -2476,7 +2476,7 @@ def test_remote(self):
24762476authkey = os.urandom(32)
2477247724782478manager = QueueManager(
2479-address=(test.support.HOST, 0), authkey=authkey, serializer=SERIALIZER
2479+address=(support.HOST, 0), authkey=authkey, serializer=SERIALIZER
24802480 )
24812481manager.start()
24822482@@ -2513,7 +2513,7 @@ def _putter(cls, address, authkey):
25132513def test_rapid_restart(self):
25142514authkey = os.urandom(32)
25152515manager = QueueManager(
2516-address=(test.support.HOST, 0), authkey=authkey, serializer=SERIALIZER)
2516+address=(support.HOST, 0), authkey=authkey, serializer=SERIALIZER)
25172517srvr = manager.get_server()
25182518addr = srvr.address
25192519# Close the connection.Listener socket which gets opened as a part
@@ -2736,14 +2736,14 @@ def test_fd_transfer(self):
27362736p = self.Process(target=self._writefd, args=(child_conn, b"foo"))
27372737p.daemon = True
27382738p.start()
2739-self.addCleanup(test.support.unlink, test.support.TESTFN)
2740-with open(test.support.TESTFN, "wb") as f:
2739+self.addCleanup(support.unlink, support.TESTFN)
2740+with open(support.TESTFN, "wb") as f:
27412741fd = f.fileno()
27422742if msvcrt:
27432743fd = msvcrt.get_osfhandle(fd)
27442744reduction.send_handle(conn, fd, p.pid)
27452745p.join()
2746-with open(test.support.TESTFN, "rb") as f:
2746+with open(support.TESTFN, "rb") as f:
27472747self.assertEqual(f.read(), b"foo")
2748274827492749@unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
@@ -2762,8 +2762,8 @@ def test_large_fd_transfer(self):
27622762p = self.Process(target=self._writefd, args=(child_conn, b"bar", True))
27632763p.daemon = True
27642764p.start()
2765-self.addCleanup(test.support.unlink, test.support.TESTFN)
2766-with open(test.support.TESTFN, "wb") as f:
2765+self.addCleanup(support.unlink, support.TESTFN)
2766+with open(support.TESTFN, "wb") as f:
27672767fd = f.fileno()
27682768for newfd in range(256, MAXFD):
27692769if not self._is_fd_assigned(newfd):
@@ -2776,7 +2776,7 @@ def test_large_fd_transfer(self):
27762776finally:
27772777os.close(newfd)
27782778p.join()
2779-with open(test.support.TESTFN, "rb") as f:
2779+with open(support.TESTFN, "rb") as f:
27802780self.assertEqual(f.read(), b"bar")
2781278127822782@classmethod
@@ -2986,7 +2986,7 @@ def _listener(cls, conn, families):
29862986l.close()
2987298729882988l = socket.socket()
2989-l.bind((test.support.HOST, 0))
2989+l.bind((support.HOST, 0))
29902990l.listen()
29912991conn.send(l.getsockname())
29922992new_conn, addr = l.accept()
@@ -3336,7 +3336,7 @@ def make_finalizers():
33363336gc.set_threshold(5, 5, 5)
33373337threads = [threading.Thread(target=run_finalizers),
33383338threading.Thread(target=make_finalizers)]
3339-with test.support.start_threads(threads):
3339+with support.start_threads(threads):
33403340time.sleep(4.0) # Wait a bit to trigger race condition
33413341finish = True
33423342if exc is not None:
@@ -3697,7 +3697,7 @@ def _child_test_wait_socket(cls, address, slow):
36973697def test_wait_socket(self, slow=False):
36983698from multiprocessing.connection import wait
36993699l = socket.socket()
3700-l.bind((test.support.HOST, 0))
3700+l.bind((support.HOST, 0))
37013701l.listen()
37023702addr = l.getsockname()
37033703readers = []
@@ -3910,11 +3910,11 @@ def test_noforkbomb(self):
39103910sm = multiprocessing.get_start_method()
39113911name = os.path.join(os.path.dirname(__file__), 'mp_fork_bomb.py')
39123912if sm != 'fork':
3913-rc, out, err = test.support.script_helper.assert_python_failure(name, sm)
3913+rc, out, err = support.script_helper.assert_python_failure(name, sm)
39143914self.assertEqual(out, b'')
39153915self.assertIn(b'RuntimeError', err)
39163916else:
3917-rc, out, err = test.support.script_helper.assert_python_ok(name, sm)
3917+rc, out, err = support.script_helper.assert_python_ok(name, sm)
39183918self.assertEqual(out.rstrip(), b'123')
39193919self.assertEqual(err, b'')
39203920@@ -4021,6 +4021,9 @@ def test_closefd(self):
4021402140224022class TestIgnoreEINTR(unittest.TestCase):
402340234024+# Sending CONN_MAX_SIZE bytes into a multiprocessing pipe must block
4025+CONN_MAX_SIZE = max(support.PIPE_MAX_SIZE, support.SOCK_MAX_SIZE)
4026+40244027@classmethod
40254028def _test_ignore(cls, conn):
40264029def handler(signum, frame):
@@ -4029,7 +4032,7 @@ def handler(signum, frame):
40294032conn.send('ready')
40304033x = conn.recv()
40314034conn.send(x)
4032-conn.send_bytes(b'x' * test.support.PIPE_MAX_SIZE)
4035+conn.send_bytes(b'x' * cls.CONN_MAX_SIZE)
4033403640344037@unittest.skipUnless(hasattr(signal, 'SIGUSR1'), 'requires SIGUSR1')
40354038def test_ignore(self):
@@ -4048,8 +4051,7 @@ def test_ignore(self):
40484051self.assertEqual(conn.recv(), 1234)
40494052time.sleep(0.1)
40504053os.kill(p.pid, signal.SIGUSR1)
4051-self.assertEqual(conn.recv_bytes(),
4052-b'x' * test.support.PIPE_MAX_SIZE)
4054+self.assertEqual(conn.recv_bytes(), b'x' * self.CONN_MAX_SIZE)
40534055time.sleep(0.1)
40544056p.join()
40554057finally:
@@ -4145,7 +4147,7 @@ def test_preload_resources(self):
41454147if multiprocessing.get_start_method() != 'forkserver':
41464148self.skipTest("test only relevant for 'forkserver' method")
41474149name = os.path.join(os.path.dirname(__file__), 'mp_preload.py')
4148-rc, out, err = test.support.script_helper.assert_python_ok(name)
4150+rc, out, err = support.script_helper.assert_python_ok(name)
41494151out = out.decode()
41504152err = err.decode()
41514153if out.rstrip() != 'ok' or err != '':
@@ -4279,7 +4281,7 @@ def setUpClass(cls):
42794281def tearDownClass(cls):
42804282# bpo-26762: Some multiprocessing objects like Pool create reference
42814283# cycles. Trigger a garbage collection to break these cycles.
4282-test.support.gc_collect()
4284+support.gc_collect()
4283428542844286processes = set(multiprocessing.process._dangling) - set(cls.dangling[0])
42854287if processes:
@@ -4458,7 +4460,7 @@ def tearDownModule():
4458446044594461# bpo-26762: Some multiprocessing objects like Pool create reference
44604462# cycles. Trigger a garbage collection to break these cycles.
4461-test.support.gc_collect()
4463+support.gc_collect()
4462446444634465multiprocessing.set_start_method(old_start_method[0], force=True)
44644466# pause a bit so we don't get warning about dangling threads/processes
@@ -4480,7 +4482,7 @@ def tearDownModule():
44804482if need_sleep:
44814483time.sleep(0.5)
44824484multiprocessing.process._cleanup()
4483-test.support.gc_collect()
4485+support.gc_collect()
4484448644854487remote_globs['setUpModule'] = setUpModule
44864488remote_globs['tearDownModule'] = tearDownModule