Skip to content

Commit bfb1f00

Browse files
[3.12] gh-76106: Remove the cleanup lock in test_socket (GH-110539) (GH-110699)
It does not already work (because it locks only addCleanup(), not doCleanups()), and it is no longer needed since the clean up procedure waits for all test threads to join. (cherry picked from commit f27b830) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 1ea4cb1 commit bfb1f00

File tree

1 file changed

+2
-24
lines changed

1 file changed

+2
-24
lines changed

Lib/test/test_socket.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -215,26 +215,6 @@ def setUp(self):
215215
self.serv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDPLITE)
216216
self.port = socket_helper.bind_port(self.serv)
217217

218-
class ThreadSafeCleanupTestCase:
219-
"""Subclass of unittest.TestCase with thread-safe cleanup methods.
220-
221-
This subclass protects the addCleanup() method with a recursive lock.
222-
223-
doCleanups() is called when the server completed, but the client can still
224-
be running in its thread especially if the server failed with a timeout.
225-
Don't put a lock on doCleanups() to prevent deadlock between addCleanup()
226-
called in the client and doCleanups() waiting for self.done.wait of
227-
ThreadableTest._setUp() (gh-110167)
228-
"""
229-
230-
def __init__(self, *args, **kwargs):
231-
super().__init__(*args, **kwargs)
232-
self._cleanup_lock = threading.RLock()
233-
234-
def addCleanup(self, *args, **kwargs):
235-
with self._cleanup_lock:
236-
return super().addCleanup(*args, **kwargs)
237-
238218

239219
class SocketCANTest(unittest.TestCase):
240220

@@ -628,8 +608,7 @@ def setUp(self):
628608
self.serv.listen()
629609

630610

631-
class ThreadedSocketTestMixin(ThreadSafeCleanupTestCase, SocketTestBase,
632-
ThreadableTest):
611+
class ThreadedSocketTestMixin(SocketTestBase, ThreadableTest):
633612
"""Mixin to add client socket and allow client/server tests.
634613
635614
Client socket is self.cli and its address is self.cli_addr. See
@@ -2815,7 +2794,7 @@ def _testRecvFromNegative(self):
28152794
# here assumes that datagram delivery on the local machine will be
28162795
# reliable.
28172796

2818-
class SendrecvmsgBase(ThreadSafeCleanupTestCase):
2797+
class SendrecvmsgBase:
28192798
# Base class for sendmsg()/recvmsg() tests.
28202799

28212800
# Time in seconds to wait before considering a test failed, or
@@ -4681,7 +4660,6 @@ def testInterruptedRecvmsgIntoTimeout(self):
46814660
@unittest.skipUnless(hasattr(signal, "alarm") or hasattr(signal, "setitimer"),
46824661
"Don't have signal.alarm or signal.setitimer")
46834662
class InterruptedSendTimeoutTest(InterruptedTimeoutBase,
4684-
ThreadSafeCleanupTestCase,
46854663
SocketListeningTestMixin, TCPTestBase):
46864664
# Test interrupting the interruptible send*() methods with signals
46874665
# when a timeout is set.

0 commit comments

Comments
 (0)