[
https://issues.apache.org/jira/browse/THRIFT-3618?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15144838#comment-15144838
]
ASF GitHub Bot commented on THRIFT-3618:
----------------------------------------
Github user nsuke commented on a diff in the pull request:
https://github.com/apache/thrift/pull/850#discussion_r52765986
--- 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 --
Just FIY, this is the issue
https://issues.apache.org/jira/browse/THRIFT-3618
> Python TSSLSocket deprecation message should print caller's location
> --------------------------------------------------------------------
>
> Key: THRIFT-3618
> URL: https://issues.apache.org/jira/browse/THRIFT-3618
> Project: Thrift
> Issue Type: Bug
> Components: Python - Library
> Reporter: Aki Sukegawa
> Assignee: Aki Sukegawa
> Priority: Minor
>
> deprecation message should print exactly where the method is called, but
> currently it is printing out the location where the message is emitted.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)