summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2021-09-16 10:30:00 (GMT)
committerGitHub <noreply@github.com>2021-09-16 10:30:00 (GMT)
commit7dacb70485a0910eb298c24b4d051720ca56fb91 (patch)
treeeaa8c46a30400d00a57ef20fc28e215971ddd8c4
parent800bd01b6d365156403c3dde61765dc5fdbf64be (diff)
downloadcpython-7dacb70485a0910eb298c24b4d051720ca56fb91.zip
cpython-7dacb70485a0910eb298c24b4d051720ca56fb91.tar.gz
cpython-7dacb70485a0910eb298c24b4d051720ca56fb91.tar.bz2
bpo-45212: Fix dangling threads in skipped tests in test_socket (GH-28361)
tearDown() is not called if setUp() raises an exception (including SkipTest). addCleanup() should be used for guaranteed execution of the cleanup code.
-rwxr-xr-xLib/test/test_socket.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 7ac9260..382e726 100755
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -326,9 +326,7 @@ class ThreadableTest:
def __init__(self):
# Swap the true setup function
self.__setUp = self.setUp
- self.__tearDown = self.tearDown
self.setUp = self._setUp
- self.tearDown = self._tearDown
def serverExplicitReady(self):
"""This method allows the server to explicitly indicate that
@@ -340,6 +338,7 @@ class ThreadableTest:
def _setUp(self):
self.wait_threads = threading_helper.wait_threads_exit()
self.wait_threads.__enter__()
+ self.addCleanup(self.wait_threads.__exit__, None, None, None)
self.server_ready = threading.Event()
self.client_ready = threading.Event()
@@ -347,6 +346,11 @@ class ThreadableTest:
self.queue = queue.Queue(1)
self.server_crashed = False
+ def raise_queued_exception():
+ if self.queue.qsize():
+ raise self.queue.get()
+ self.addCleanup(raise_queued_exception)
+
# Do some munging to start the client test.
methodname = self.id()
i = methodname.rfind('.')
@@ -363,15 +367,7 @@ class ThreadableTest:
finally:
self.server_ready.set()
self.client_ready.wait()
-
- def _tearDown(self):
- self.__tearDown()
- self.done.wait()
- self.wait_threads.__exit__(None, None, None)
-
- if self.queue.qsize():
- exc = self.queue.get()
- raise exc
+ self.addCleanup(self.done.wait)
def clientRun(self, test_func):
self.server_ready.wait()
@@ -6211,6 +6207,7 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest):
def testWithTimeoutTriggeredSend(self):
conn = self.accept_conn()
conn.recv(88192)
+ time.sleep(1)
# errors