diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 7ac92608f7c..382e72630dd 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