diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2017-11-09 16:35:44 -0800 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2017-11-09 16:35:44 -0800 |
commit | cc0089b028f5a56d4846791f79ffe8cc37ce5c3b (patch) | |
tree | 74fb32e1aa1784ae5504354513c226dac9b0737b /tests/test_client.py | |
parent | 84ce0d5c04092c5116ee3aa64445581bf142e562 (diff) |
Prevent test suite hangs
Diffstat (limited to 'tests/test_client.py')
-rw-r--r-- | tests/test_client.py | 19 |
1 files changed, 16 insertions, 3 deletions
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: |