Skip to content

Commit 64e538b

Browse files
authored
bpo-33532: Fix test_multiprocessing_forkserver.test_ignore() (GH-7322)
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.
1 parent 137e803 commit 64e538b

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
import struct
2121
import operator
2222
import weakref
23-
import test.support
23+
from test import support
2424
import test.support.script_helper
2525

2626

2727
# 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):
567567
if self.TYPE == "threads":
568568
self.skipTest('test not appropriate for {}'.format(self.TYPE))
569569

570-
testfn = test.support.TESTFN
571-
self.addCleanup(test.support.unlink, testfn)
570+
testfn = support.TESTFN
571+
self.addCleanup(support.unlink, testfn)
572572
proc = self.Process(target=self._test_stderr_flush, args=(testfn,))
573573
proc.start()
574574
proc.join()
@@ -597,8 +597,8 @@ def test_sys_exit(self):
597597
if self.TYPE == 'threads':
598598
self.skipTest('test not appropriate for {}'.format(self.TYPE))
599599

600-
testfn = test.support.TESTFN
601-
self.addCleanup(test.support.unlink, testfn)
600+
testfn = support.TESTFN
601+
self.addCleanup(support.unlink, testfn)
602602

603603
for reason in (
604604
[1, 2, 3],
@@ -853,7 +853,7 @@ def test_task_done(self):
853853
close_queue(queue)
854854

855855
def test_no_import_lock_contention(self):
856-
with test.support.temp_cwd():
856+
with support.temp_cwd():
857857
module_name = 'imported_by_an_imported_module'
858858
with open(module_name + '.py', 'w') as f:
859859
f.write("""if 1:
@@ -866,7 +866,7 @@ def test_no_import_lock_contention(self):
866866
del q
867867
""")
868868

869-
with test.support.DirsOnSysPath(os.getcwd()):
869+
with support.DirsOnSysPath(os.getcwd()):
870870
try:
871871
__import__(module_name)
872872
except pyqueue.Empty:
@@ -891,7 +891,7 @@ def test_queue_feeder_donot_stop_onexc(self):
891891
class NotSerializable(object):
892892
def __reduce__(self):
893893
raise AttributeError
894-
with test.support.captured_stderr():
894+
with support.captured_stderr():
895895
q = self.Queue()
896896
q.put(NotSerializable())
897897
q.put(True)
@@ -2194,7 +2194,7 @@ def test_traceback(self):
21942194
self.assertIs(type(cause), multiprocessing.pool.RemoteTraceback)
21952195
self.assertIn('raise RuntimeError(123) # some comment', cause.tb)
21962196

2197-
with test.support.captured_stderr() as f1:
2197+
with support.captured_stderr() as f1:
21982198
try:
21992199
raise exc
22002200
except RuntimeError:
@@ -2476,7 +2476,7 @@ def test_remote(self):
24762476
authkey = os.urandom(32)
24772477

24782478
manager = QueueManager(
2479-
address=(test.support.HOST, 0), authkey=authkey, serializer=SERIALIZER
2479+
address=(support.HOST, 0), authkey=authkey, serializer=SERIALIZER
24802480
)
24812481
manager.start()
24822482

@@ -2513,7 +2513,7 @@ def _putter(cls, address, authkey):
25132513
def test_rapid_restart(self):
25142514
authkey = os.urandom(32)
25152515
manager = QueueManager(
2516-
address=(test.support.HOST, 0), authkey=authkey, serializer=SERIALIZER)
2516+
address=(support.HOST, 0), authkey=authkey, serializer=SERIALIZER)
25172517
srvr = manager.get_server()
25182518
addr = srvr.address
25192519
# Close the connection.Listener socket which gets opened as a part
@@ -2736,14 +2736,14 @@ def test_fd_transfer(self):
27362736
p = self.Process(target=self._writefd, args=(child_conn, b"foo"))
27372737
p.daemon = True
27382738
p.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:
27412741
fd = f.fileno()
27422742
if msvcrt:
27432743
fd = msvcrt.get_osfhandle(fd)
27442744
reduction.send_handle(conn, fd, p.pid)
27452745
p.join()
2746-
with open(test.support.TESTFN, "rb") as f:
2746+
with open(support.TESTFN, "rb") as f:
27472747
self.assertEqual(f.read(), b"foo")
27482748

27492749
@unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
@@ -2762,8 +2762,8 @@ def test_large_fd_transfer(self):
27622762
p = self.Process(target=self._writefd, args=(child_conn, b"bar", True))
27632763
p.daemon = True
27642764
p.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:
27672767
fd = f.fileno()
27682768
for newfd in range(256, MAXFD):
27692769
if not self._is_fd_assigned(newfd):
@@ -2776,7 +2776,7 @@ def test_large_fd_transfer(self):
27762776
finally:
27772777
os.close(newfd)
27782778
p.join()
2779-
with open(test.support.TESTFN, "rb") as f:
2779+
with open(support.TESTFN, "rb") as f:
27802780
self.assertEqual(f.read(), b"bar")
27812781

27822782
@classmethod
@@ -2986,7 +2986,7 @@ def _listener(cls, conn, families):
29862986
l.close()
29872987

29882988
l = socket.socket()
2989-
l.bind((test.support.HOST, 0))
2989+
l.bind((support.HOST, 0))
29902990
l.listen()
29912991
conn.send(l.getsockname())
29922992
new_conn, addr = l.accept()
@@ -3336,7 +3336,7 @@ def make_finalizers():
33363336
gc.set_threshold(5, 5, 5)
33373337
threads = [threading.Thread(target=run_finalizers),
33383338
threading.Thread(target=make_finalizers)]
3339-
with test.support.start_threads(threads):
3339+
with support.start_threads(threads):
33403340
time.sleep(4.0) # Wait a bit to trigger race condition
33413341
finish = True
33423342
if exc is not None:
@@ -3697,7 +3697,7 @@ def _child_test_wait_socket(cls, address, slow):
36973697
def test_wait_socket(self, slow=False):
36983698
from multiprocessing.connection import wait
36993699
l = socket.socket()
3700-
l.bind((test.support.HOST, 0))
3700+
l.bind((support.HOST, 0))
37013701
l.listen()
37023702
addr = l.getsockname()
37033703
readers = []
@@ -3910,11 +3910,11 @@ def test_noforkbomb(self):
39103910
sm = multiprocessing.get_start_method()
39113911
name = os.path.join(os.path.dirname(__file__), 'mp_fork_bomb.py')
39123912
if 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)
39143914
self.assertEqual(out, b'')
39153915
self.assertIn(b'RuntimeError', err)
39163916
else:
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)
39183918
self.assertEqual(out.rstrip(), b'123')
39193919
self.assertEqual(err, b'')
39203920

@@ -4021,6 +4021,9 @@ def test_closefd(self):
40214021

40224022
class TestIgnoreEINTR(unittest.TestCase):
40234023

4024+
# 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
40254028
def _test_ignore(cls, conn):
40264029
def handler(signum, frame):
@@ -4029,7 +4032,7 @@ def handler(signum, frame):
40294032
conn.send('ready')
40304033
x = conn.recv()
40314034
conn.send(x)
4032-
conn.send_bytes(b'x' * test.support.PIPE_MAX_SIZE)
4035+
conn.send_bytes(b'x' * cls.CONN_MAX_SIZE)
40334036

40344037
@unittest.skipUnless(hasattr(signal, 'SIGUSR1'), 'requires SIGUSR1')
40354038
def test_ignore(self):
@@ -4048,8 +4051,7 @@ def test_ignore(self):
40484051
self.assertEqual(conn.recv(), 1234)
40494052
time.sleep(0.1)
40504053
os.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)
40534055
time.sleep(0.1)
40544056
p.join()
40554057
finally:
@@ -4145,7 +4147,7 @@ def test_preload_resources(self):
41454147
if multiprocessing.get_start_method() != 'forkserver':
41464148
self.skipTest("test only relevant for 'forkserver' method")
41474149
name = 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)
41494151
out = out.decode()
41504152
err = err.decode()
41514153
if out.rstrip() != 'ok' or err != '':
@@ -4279,7 +4281,7 @@ def setUpClass(cls):
42794281
def 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()
42834285

42844286
processes = set(multiprocessing.process._dangling) - set(cls.dangling[0])
42854287
if processes:
@@ -4458,7 +4460,7 @@ def tearDownModule():
44584460

44594461
# 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()
44624464

44634465
multiprocessing.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():
44804482
if need_sleep:
44814483
time.sleep(0.5)
44824484
multiprocessing.process._cleanup()
4483-
test.support.gc_collect()
4485+
support.gc_collect()
44844486

44854487
remote_globs['setUpModule'] = setUpModule
44864488
remote_globs['tearDownModule'] = tearDownModule

0 commit comments

Comments
 (0)