You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by jsirois <gi...@git.apache.org> on 2016/02/12 16:14:32 UTC
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
GitHub user jsirois opened a pull request:
https://github.com/apache/thrift/pull/850
lib/py/test/test_sslsocket.py is flaky
Previously a combination of fixed ports, fixed paths and delays was used
in all TSSLSocketTest tests that involved making a client-server
connection; now ephemeral ports, unique tmp files and no delays for
successful connection tests are all implemented. A delay still remains
for the failed connection tests to allow for SSL handshake initiation
but not wait too long.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/jsirois/thrift THRIFT-3616
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/thrift/pull/850.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #850
----
commit ccc526da5bdfaf65e94a88e2e3350648ba2931c4
Author: John Sirois <js...@apache.org>
Date: 2016-02-12T15:10:13Z
Improve TSSLSocketTest robustness.
Previously a combination of fixed ports, fixed paths and delays was used
in all TSSLSocketTest tests that involved making a client-server
connection; now ephemeral ports, unique tmp files and no delays for
successful connection tests are all implemented. A delay still remains
for the failed connection tests to allow for SSL handshake initiation
but not wait too long.
----
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
Posted by nsuke <gi...@git.apache.org>.
Github user nsuke commented on a diff in the pull request:
https://github.com/apache/thrift/pull/850#discussion_r52768604
--- 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()
--- End diff --
Ah, I think I finally got it.
Maybe you mean `self._listening.wait(timeout=timeout)` rather than `_port_bound` here ?
I missed your intention of waiting for `listen()` rather than `getsockname()`
Could you change it to _listening or remove the _listening that is unused ?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
Posted by nsuke <gi...@git.apache.org>.
Github user nsuke commented on a diff in the pull request:
https://github.com/apache/thrift/pull/850#discussion_r52764385
--- 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 --
For some reason, deprecation count now differs between Python 2 and Python 3
https://travis-ci.org/apache/thrift/jobs/108805112#L2383
> File "test/test_sslsocket.py", line 164, in test_deprecation
> self.assertEqual(len(w), 7)
> AssertionError: 6 != 7
I've found another issue on deprecate messages so I'll need to modify this part shortly after, after all.
So you can just skip this with if + print for now.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
Posted by jsirois <gi...@git.apache.org>.
Github user jsirois commented on the pull request:
https://github.com/apache/thrift/pull/850#issuecomment-183369497
@nsuke - hoping you have time to review this one
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
Posted by jsirois <gi...@git.apache.org>.
Github user jsirois commented on a diff in the pull request:
https://github.com/apache/thrift/pull/850#discussion_r52765017
--- Diff: lib/py/test/test_sslsocket.py ---
@@ -42,22 +43,50 @@
CLIENT_KEY = os.path.join(ROOT_DIR, 'test', 'keys', 'client_v3.key')
CLIENT_CA = os.path.join(ROOT_DIR, 'test', 'keys', 'CA.pem')
-TEST_PORT = 23458
-TEST_ADDR = '/tmp/.thrift.domain.sock.%d' % TEST_PORT
-CONNECT_DELAY = 0.5
-CONNECT_TIMEOUT = 20.0
TEST_CIPHERS = 'DES-CBC3-SHA'
class ServerAcceptor(threading.Thread):
def __init__(self, server):
super(ServerAcceptor, self).__init__()
+ self.daemon = True
self._server = server
- self.client = None
+ self._listening = threading.Event()
+ self._port = None
+ self._port_bound = threading.Event()
+ self._client = None
+ self._client_accepted = threading.Event()
def run(self):
self._server.listen()
- self.client = self._server.accept()
+ self._listening.set()
+
+ try:
+ address = self._server.handle.getsockname()
+ if len(address) > 1:
+ # AF_INET addresses are 2-tuples (host, port) and AF_INET6 are
+ # 4-tuples (host, port, ...), but in each case port is in the second slot.
+ self._port = address[1]
+ finally:
+ self._port_bound.set()
+
+ try:
+ self._client = self._server.accept()
+ finally:
+ self._client_accepted.set()
+
+ def await_listening(self, timeout=None):
+ self._port_bound.wait(timeout=timeout)
+
+ @property
+ def port(self, timeout=None):
--- End diff --
This is used below on line 117
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
Posted by jsirois <gi...@git.apache.org>.
Github user jsirois commented on a diff in the pull request:
https://github.com/apache/thrift/pull/850#discussion_r52766421
--- Diff: lib/py/test/test_sslsocket.py ---
@@ -42,22 +43,50 @@
CLIENT_KEY = os.path.join(ROOT_DIR, 'test', 'keys', 'client_v3.key')
CLIENT_CA = os.path.join(ROOT_DIR, 'test', 'keys', 'CA.pem')
-TEST_PORT = 23458
-TEST_ADDR = '/tmp/.thrift.domain.sock.%d' % TEST_PORT
-CONNECT_DELAY = 0.5
-CONNECT_TIMEOUT = 20.0
TEST_CIPHERS = 'DES-CBC3-SHA'
class ServerAcceptor(threading.Thread):
def __init__(self, server):
super(ServerAcceptor, self).__init__()
+ self.daemon = True
self._server = server
- self.client = None
+ self._listening = threading.Event()
+ self._port = None
+ self._port_bound = threading.Event()
+ self._client = None
+ self._client_accepted = threading.Event()
def run(self):
self._server.listen()
- self.client = self._server.accept()
+ self._listening.set()
+
+ try:
+ address = self._server.handle.getsockname()
+ if len(address) > 1:
+ # AF_INET addresses are 2-tuples (host, port) and AF_INET6 are
+ # 4-tuples (host, port, ...), but in each case port is in the second slot.
+ self._port = address[1]
+ finally:
+ self._port_bound.set()
+
+ try:
+ self._client = self._server.accept()
+ finally:
+ self._client_accepted.set()
+
+ def await_listening(self, timeout=None):
+ self._port_bound.wait(timeout=timeout)
+
+ @property
+ def port(self, timeout=None):
--- End diff --
Aha - gotcha, will do. One more diff coming.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
Posted by jsirois <gi...@git.apache.org>.
Github user jsirois commented on a diff in the pull request:
https://github.com/apache/thrift/pull/850#discussion_r52766891
--- 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 --
Added a link to the issue in the comment - thanks!
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
Posted by nsuke <gi...@git.apache.org>.
Github user nsuke commented on a diff in the pull request:
https://github.com/apache/thrift/pull/850#discussion_r52766168
--- Diff: lib/py/test/test_sslsocket.py ---
@@ -42,22 +43,50 @@
CLIENT_KEY = os.path.join(ROOT_DIR, 'test', 'keys', 'client_v3.key')
CLIENT_CA = os.path.join(ROOT_DIR, 'test', 'keys', 'CA.pem')
-TEST_PORT = 23458
-TEST_ADDR = '/tmp/.thrift.domain.sock.%d' % TEST_PORT
-CONNECT_DELAY = 0.5
-CONNECT_TIMEOUT = 20.0
TEST_CIPHERS = 'DES-CBC3-SHA'
class ServerAcceptor(threading.Thread):
def __init__(self, server):
super(ServerAcceptor, self).__init__()
+ self.daemon = True
self._server = server
- self.client = None
+ self._listening = threading.Event()
+ self._port = None
+ self._port_bound = threading.Event()
+ self._client = None
+ self._client_accepted = threading.Event()
def run(self):
self._server.listen()
- self.client = self._server.accept()
+ self._listening.set()
+
+ try:
+ address = self._server.handle.getsockname()
+ if len(address) > 1:
+ # AF_INET addresses are 2-tuples (host, port) and AF_INET6 are
+ # 4-tuples (host, port, ...), but in each case port is in the second slot.
+ self._port = address[1]
+ finally:
+ self._port_bound.set()
+
+ try:
+ self._client = self._server.accept()
+ finally:
+ self._client_accepted.set()
+
+ def await_listening(self, timeout=None):
+ self._port_bound.wait(timeout=timeout)
+
+ @property
+ def port(self, timeout=None):
--- End diff --
Oops, edit was too late, please check the above out.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
Posted by jsirois <gi...@git.apache.org>.
Github user jsirois commented on the pull request:
https://github.com/apache/thrift/pull/850#issuecomment-183379947
Noting that Jenkins CI failed on lib/cpp/test/SecurityTest.cpp before getting to test_sslsocket.py.
I have a fix for the SecurityTest in #848 that still needs review attention so I'll mark THRIFT-3616 as blocked on THRIFT-3608
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
Posted by nsuke <gi...@git.apache.org>.
Github user nsuke commented on a diff in the pull request:
https://github.com/apache/thrift/pull/850#discussion_r52764799
--- Diff: lib/py/test/test_sslsocket.py ---
@@ -42,22 +43,50 @@
CLIENT_KEY = os.path.join(ROOT_DIR, 'test', 'keys', 'client_v3.key')
CLIENT_CA = os.path.join(ROOT_DIR, 'test', 'keys', 'CA.pem')
-TEST_PORT = 23458
-TEST_ADDR = '/tmp/.thrift.domain.sock.%d' % TEST_PORT
-CONNECT_DELAY = 0.5
-CONNECT_TIMEOUT = 20.0
TEST_CIPHERS = 'DES-CBC3-SHA'
class ServerAcceptor(threading.Thread):
def __init__(self, server):
super(ServerAcceptor, self).__init__()
+ self.daemon = True
self._server = server
- self.client = None
+ self._listening = threading.Event()
+ self._port = None
+ self._port_bound = threading.Event()
+ self._client = None
+ self._client_accepted = threading.Event()
def run(self):
self._server.listen()
- self.client = self._server.accept()
+ self._listening.set()
+
+ try:
+ address = self._server.handle.getsockname()
+ if len(address) > 1:
+ # AF_INET addresses are 2-tuples (host, port) and AF_INET6 are
+ # 4-tuples (host, port, ...), but in each case port is in the second slot.
+ self._port = address[1]
+ finally:
+ self._port_bound.set()
+
+ try:
+ self._client = self._server.accept()
+ finally:
+ self._client_accepted.set()
+
+ def await_listening(self, timeout=None):
+ self._port_bound.wait(timeout=timeout)
+
+ @property
+ def port(self, timeout=None):
--- End diff --
property argument is unusable, but fortunately not needed either.
Could you remove this ?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
Posted by nsuke <gi...@git.apache.org>.
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
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
Posted by jsirois <gi...@git.apache.org>.
Github user jsirois commented on a diff in the pull request:
https://github.com/apache/thrift/pull/850#discussion_r52769020
--- 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()
--- End diff --
Aha - that was copypasta - fixed to make `await_listening` use the `_listening` `Event` which was the intention all along.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/thrift/pull/850
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
Posted by jsirois <gi...@git.apache.org>.
Github user jsirois commented on a diff in the pull request:
https://github.com/apache/thrift/pull/850#discussion_r52765133
--- Diff: lib/py/test/test_sslsocket.py ---
@@ -42,22 +43,50 @@
CLIENT_KEY = os.path.join(ROOT_DIR, 'test', 'keys', 'client_v3.key')
CLIENT_CA = os.path.join(ROOT_DIR, 'test', 'keys', 'CA.pem')
-TEST_PORT = 23458
-TEST_ADDR = '/tmp/.thrift.domain.sock.%d' % TEST_PORT
-CONNECT_DELAY = 0.5
-CONNECT_TIMEOUT = 20.0
TEST_CIPHERS = 'DES-CBC3-SHA'
class ServerAcceptor(threading.Thread):
def __init__(self, server):
super(ServerAcceptor, self).__init__()
+ self.daemon = True
self._server = server
- self.client = None
+ self._listening = threading.Event()
+ self._port = None
+ self._port_bound = threading.Event()
+ self._client = None
+ self._client_accepted = threading.Event()
def run(self):
self._server.listen()
- self.client = self._server.accept()
+ self._listening.set()
+
+ try:
+ address = self._server.handle.getsockname()
+ if len(address) > 1:
+ # AF_INET addresses are 2-tuples (host, port) and AF_INET6 are
+ # 4-tuples (host, port, ...), but in each case port is in the second slot.
+ self._port = address[1]
+ finally:
+ self._port_bound.set()
+
+ try:
+ self._client = self._server.accept()
+ finally:
+ self._client_accepted.set()
+
+ def await_listening(self, timeout=None):
+ self._port_bound.wait(timeout=timeout)
+
+ @property
+ def port(self, timeout=None):
+ self._port_bound.wait(timeout=timeout)
+ return self._port
+
+ @property
+ def client(self, timeout=None):
+ self._client_accepted.wait(timeout=timeout)
--- End diff --
Used on lines 134 and 148 below.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
Posted by nsuke <gi...@git.apache.org>.
Github user nsuke commented on a diff in the pull request:
https://github.com/apache/thrift/pull/850#discussion_r52764647
--- 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()
--- End diff --
You've merged `_port_bound.wait` to `port` property so this method is no longer needed ?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
Posted by jsirois <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
Posted by nsuke <gi...@git.apache.org>.
Github user nsuke commented on a diff in the pull request:
https://github.com/apache/thrift/pull/850#discussion_r52764813
--- Diff: lib/py/test/test_sslsocket.py ---
@@ -42,22 +43,50 @@
CLIENT_KEY = os.path.join(ROOT_DIR, 'test', 'keys', 'client_v3.key')
CLIENT_CA = os.path.join(ROOT_DIR, 'test', 'keys', 'CA.pem')
-TEST_PORT = 23458
-TEST_ADDR = '/tmp/.thrift.domain.sock.%d' % TEST_PORT
-CONNECT_DELAY = 0.5
-CONNECT_TIMEOUT = 20.0
TEST_CIPHERS = 'DES-CBC3-SHA'
class ServerAcceptor(threading.Thread):
def __init__(self, server):
super(ServerAcceptor, self).__init__()
+ self.daemon = True
self._server = server
- self.client = None
+ self._listening = threading.Event()
+ self._port = None
+ self._port_bound = threading.Event()
+ self._client = None
+ self._client_accepted = threading.Event()
def run(self):
self._server.listen()
- self.client = self._server.accept()
+ self._listening.set()
+
+ try:
+ address = self._server.handle.getsockname()
+ if len(address) > 1:
+ # AF_INET addresses are 2-tuples (host, port) and AF_INET6 are
+ # 4-tuples (host, port, ...), but in each case port is in the second slot.
+ self._port = address[1]
+ finally:
+ self._port_bound.set()
+
+ try:
+ self._client = self._server.accept()
+ finally:
+ self._client_accepted.set()
+
+ def await_listening(self, timeout=None):
+ self._port_bound.wait(timeout=timeout)
+
+ @property
+ def port(self, timeout=None):
+ self._port_bound.wait(timeout=timeout)
+ return self._port
+
+ @property
+ def client(self, timeout=None):
+ self._client_accepted.wait(timeout=timeout)
--- End diff --
same as above
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] thrift pull request: lib/py/test/test_sslsocket.py is flaky
Posted by jsirois <gi...@git.apache.org>.
Github user jsirois commented on a diff in the pull request:
https://github.com/apache/thrift/pull/850#discussion_r52765229
--- 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()
--- End diff --
Its needed for the unix domain socket case which binds no port, but must wait for the server to be up and listening.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---