-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-33099: Fix test_poplib hangs after error #6428
Changes from 3 commits
331844a
844e994
ac1f692
f3e857d
ab6463f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import os | ||
import errno | ||
import threading | ||
import traceback | ||
|
||
from unittest import TestCase, skipUnless | ||
from test import support as test_support | ||
|
@@ -220,18 +221,21 @@ def start(self): | |
self.__flag.wait() | ||
|
||
def run(self): | ||
self.active = True | ||
self.__flag.set() | ||
while self.active and asyncore.socket_map: | ||
self.active_lock.acquire() | ||
asyncore.loop(timeout=0.1, count=1) | ||
self.active_lock.release() | ||
asyncore.close_all(ignore_all=True) | ||
try: | ||
self.active = True | ||
self.__flag.set() | ||
while self.active and asyncore.socket_map: | ||
self.active_lock.acquire() | ||
asyncore.loop(timeout=0.1, count=1) | ||
self.active_lock.release() | ||
finally: | ||
self.close() | ||
|
||
def stop(self): | ||
assert self.active | ||
self.active = False | ||
self.join() | ||
asyncore.close_all(ignore_all=True) | ||
|
||
def handle_accepted(self, conn, addr): | ||
self.handler_instance = self.handler(conn) | ||
|
@@ -254,7 +258,12 @@ def assertOK(self, resp): | |
def setUp(self): | ||
self.server = DummyPOP3Server((HOST, PORT)) | ||
self.server.start() | ||
self.client = poplib.POP3(self.server.host, self.server.port, timeout=3) | ||
try: | ||
self.client = poplib.POP3(self.server.host, self.server.port, timeout=3) | ||
except: | ||
self.server.stop() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can try:
self.server.stop()
finally:
self.server = None
raise or server = self.server
self.server = None
server.stop()
raise ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we shouldn't complicate test code for non-real errors. |
||
self.server = None | ||
raise | ||
|
||
def tearDown(self): | ||
self.client.close() | ||
|
@@ -403,7 +412,12 @@ def setUp(self): | |
self.server = DummyPOP3Server((HOST, PORT)) | ||
self.server.handler = DummyPOP3_SSLHandler | ||
self.server.start() | ||
self.client = poplib.POP3_SSL(self.server.host, self.server.port) | ||
try: | ||
self.client = poplib.POP3_SSL(self.server.host, self.server.port) | ||
except: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try/finally |
||
self.server.stop() | ||
self.server = None | ||
raise | ||
|
||
def test__all__(self): | ||
self.assertIn('POP3_SSL', poplib.__all__) | ||
|
@@ -446,8 +460,13 @@ class TestPOP3_TLSClass(TestPOP3Class): | |
def setUp(self): | ||
self.server = DummyPOP3Server((HOST, PORT)) | ||
self.server.start() | ||
self.client = poplib.POP3(self.server.host, self.server.port, timeout=3) | ||
self.client.stls() | ||
try: | ||
self.client = poplib.POP3(self.server.host, self.server.port, timeout=3) | ||
self.client.stls() | ||
except: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try/finally |
||
self.server.stop() | ||
self.server = None | ||
raise | ||
|
||
def tearDown(self): | ||
if self.client.file is not None and self.client.sock is not None: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fix test_poplib hangs when an error occured in ``setUp()`` method or | ||
``DummyPOP3Server.run()``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be try/finally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
setUp()
succeeded,tearDown()
do it.So this should be
except:
, notfinally:
.