]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-76106: Remove the cleanup lock in test_socket (GH-110539)
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 11 Oct 2023 10:52:06 +0000 (13:52 +0300)
committerGitHub <noreply@github.com>
Wed, 11 Oct 2023 10:52:06 +0000 (13:52 +0300)
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.

Lib/test/test_socket.py

index 0d1c1867a25c407c48943f43003b3213a598cca9..86701caf05399eca5b72686c1091d7724a06845f 100644 (file)
@@ -215,26 +215,6 @@ class SocketUDPLITETest(SocketUDPTest):
         self.serv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDPLITE)
         self.port = socket_helper.bind_port(self.serv)
 
-class ThreadSafeCleanupTestCase:
-    """Subclass of unittest.TestCase with thread-safe cleanup methods.
-
-    This subclass protects the addCleanup() method with a recursive lock.
-
-    doCleanups() is called when the server completed, but the client can still
-    be running in its thread especially if the server failed with a timeout.
-    Don't put a lock on doCleanups() to prevent deadlock between addCleanup()
-    called in the client and doCleanups() waiting for self.done.wait of
-    ThreadableTest._setUp() (gh-110167)
-    """
-
-    def __init__(self, *args, **kwargs):
-        super().__init__(*args, **kwargs)
-        self._cleanup_lock = threading.RLock()
-
-    def addCleanup(self, *args, **kwargs):
-        with self._cleanup_lock:
-            return super().addCleanup(*args, **kwargs)
-
 
 class SocketCANTest(unittest.TestCase):
 
@@ -628,8 +608,7 @@ class SocketListeningTestMixin(SocketTestBase):
         self.serv.listen()
 
 
-class ThreadedSocketTestMixin(ThreadSafeCleanupTestCase, SocketTestBase,
-                              ThreadableTest):
+class ThreadedSocketTestMixin(SocketTestBase, ThreadableTest):
     """Mixin to add client socket and allow client/server tests.
 
     Client socket is self.cli and its address is self.cli_addr.  See
@@ -2815,7 +2794,7 @@ class BasicUDPLITETest(ThreadedUDPLITESocketTest):
 # here assumes that datagram delivery on the local machine will be
 # reliable.
 
-class SendrecvmsgBase(ThreadSafeCleanupTestCase):
+class SendrecvmsgBase:
     # Base class for sendmsg()/recvmsg() tests.
 
     # Time in seconds to wait before considering a test failed, or
@@ -4681,7 +4660,6 @@ class InterruptedRecvTimeoutTest(InterruptedTimeoutBase, UDPTestBase):
 @unittest.skipUnless(hasattr(signal, "alarm") or hasattr(signal, "setitimer"),
                      "Don't have signal.alarm or signal.setitimer")
 class InterruptedSendTimeoutTest(InterruptedTimeoutBase,
-                                 ThreadSafeCleanupTestCase,
                                  SocketListeningTestMixin, TCPTestBase):
     # Test interrupting the interruptible send*() methods with signals
     # when a timeout is set.