diff options
-rw-r--r-- | sites/www/changelog.rst | 4 | ||||
-rw-r--r-- | tests/test_client.py | 19 |
2 files changed, 20 insertions, 3 deletions
diff --git a/sites/www/changelog.rst b/sites/www/changelog.rst index c8b584d7..e08048bd 100644 --- a/sites/www/changelog.rst +++ b/sites/www/changelog.rst @@ -2,6 +2,10 @@ Changelog ========= +* :support:`-` Update ``tearDown`` of client test suite to avoid hangs due to + eternally blocking ``accept()`` calls on the internal server thread (which + can occur when test code raises an exception before actually connecting to + the server.) * :bug:`1108 (1.17+)` Rename a private method keyword argument (which was named ``async``) so that we're compatible with the upcoming Python 3.7 release (where ``async`` is a new keyword.) Thanks to ``@vEpiphyte`` for the report. diff --git a/tests/test_client.py b/tests/test_client.py index c627e1c3..6e6a3fcb 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -126,9 +126,22 @@ class ClientTest(unittest.TestCase): self.event = threading.Event() def tearDown(self): - for attr in "tc ts socks sockl".split(): - if hasattr(self, attr): - getattr(self, attr).close() + # Shut down client Transport + if hasattr(self, 'tc'): + self.tc.close() + # Shut down shared socket + if hasattr(self, 'sockl'): + # Forcibly connect to server sock in case the server thread is + # hanging out in its accept() (e.g. if the client side of the test + # fails before it even gets to connecting); there's no other good + # way to force an accept() to exit. + put_a_sock_in_it = socket.socket() + put_a_sock_in_it.connect((self.addr, self.port)) + put_a_sock_in_it.close() + # Then close "our" end of the socket (which _should_ cause the + # accept() to bail out, but does not, for some reason. I blame + # threading.) + self.sockl.close() def _run(self, allowed_keys=None, delay=0, public_blob=None): if allowed_keys is None: |