Skip to content

Commit

Permalink
[3.11] pythongh-76106: Remove the cleanup lock in test_socket (python…
Browse files Browse the repository at this point in the history
…GH-110539) (pythonGH-110700)

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]>
  • Loading branch information
miss-islington and serhiy-storchaka authored Oct 11, 2023
1 parent a8b2d12 commit 79b81d1
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,26 +201,6 @@ def setUp(self):
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):

Expand Down Expand Up @@ -613,8 +593,7 @@ def setUp(self):
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
Expand Down Expand Up @@ -2698,7 +2677,7 @@ def _testRecvFromNegative(self):
# 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
Expand Down Expand Up @@ -4564,7 +4543,6 @@ def testInterruptedRecvmsgIntoTimeout(self):
@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.
Expand Down

0 comments on commit 79b81d1

Please sign in to comment.