Github user jsirois commented on a diff in the pull request: https://github.com/apache/thrift/pull/850#discussion_r52765381 --- Diff: lib/py/test/test_sslsocket.py --- @@ -75,185 +104,176 @@ def __exit__(self, exc_type, exc_value, traceback): class TSSLSocketTest(unittest.TestCase): - def _assert_connection_failure(self, server, client): + def _server_socket(self, **kwargs): + return TSSLServerSocket(port=0, **kwargs) + + @contextmanager + def _connectable_client(self, server, path=None, **client_kwargs): acc = ServerAcceptor(server) try: acc.start() - time.sleep(CONNECT_DELAY / 2) - client.setTimeout(CONNECT_TIMEOUT / 2) - with self._assert_raises(Exception): - logging.disable(logging.CRITICAL) - client.open() - select.select([], [client.handle], [], CONNECT_TIMEOUT / 2) - # self.assertIsNone(acc.client) - self.assertTrue(acc.client is None) + acc.await_listening() + + host, port = ('localhost', acc.port) if path is None else (None, None) + client = TSSLSocket(host, port, path, **client_kwargs) + yield acc, client finally: - logging.disable(logging.NOTSET) - client.close() if acc.client: acc.client.close() server.close() + def _assert_connection_failure(self, server, path=None, **client_args): + with self._connectable_client(server, path=path, **client_args) as (acc, client): + try: + logging.disable(logging.CRITICAL) + # We need to wait for a connection failure, but not too long. 20ms is a tunable + # compromise between test speed and stability + client.setTimeout(20) + with self._assert_raises(TTransportException): + client.open() + self.assertTrue(acc.client is None) + finally: + logging.disable(logging.NOTSET) + def _assert_raises(self, exc): if sys.hexversion >= 0x020700F0: return self.assertRaises(exc) else: return AssertRaises(exc) - def _assert_connection_success(self, server, client): - acc = ServerAcceptor(server) - try: - acc.start() - time.sleep(CONNECT_DELAY) - client.setTimeout(CONNECT_TIMEOUT) + def _assert_connection_success(self, server, path=None, **client_args): + with self._connectable_client(server, path=path, **client_args) as (acc, client): client.open() - select.select([], [client.handle], [], CONNECT_TIMEOUT) - # self.assertIsNotNone(acc.client) - self.assertTrue(acc.client is not None) - finally: - client.close() - if acc.client: - acc.client.close() - server.close() + try: + self.assertTrue(acc.client is not None) + finally: + client.close() # deprecated feature def test_deprecation(self): --- End diff -- will do - diff coming presently
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---