From 8a213925e966e36cbda5ae394bbe695746041f97 Mon Sep 17 00:00:00 2001 From: Stephen Sorriaux Date: Fri, 24 Mar 2023 17:35:53 -0400 Subject: [PATCH] fix(tests): making test_read_only test less flaky --- .../tests/{test__connection.py => test_connection.py} | 10 ++++++++-- pyproject.toml | 2 +- tox.ini | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) rename kazoo/tests/{test__connection.py => test_connection.py} (97%) diff --git a/kazoo/tests/test__connection.py b/kazoo/tests/test_connection.py similarity index 97% rename from kazoo/tests/test__connection.py rename to kazoo/tests/test_connection.py index 80a777e8..66739afc 100644 --- a/kazoo/tests/test__connection.py +++ b/kazoo/tests/test_connection.py @@ -258,7 +258,7 @@ def back(state): class TestReadOnlyMode(KazooTestCase): def setUp(self): os.environ["ZOOKEEPER_LOCAL_SESSION_RO"] = "true" - self.setup_zookeeper(read_only=True) + self.setup_zookeeper() skip = False if CI_ZK_VERSION and CI_ZK_VERSION < (3, 4): skip = True @@ -278,8 +278,13 @@ def tearDown(self): def test_read_only(self): from kazoo.exceptions import NotReadOnlyCallError from kazoo.protocol.states import KeeperState + from kazoo.retry import KazooRetry - client = self.client + conn_retry = KazooRetry(max_tries=10, delay=0.2) + client = self._get_client( + connection_retry=conn_retry, + read_only=True + ) states = [] ev = threading.Event() @@ -289,6 +294,7 @@ def listen(state): if client.client_state == KeeperState.CONNECTED_RO: ev.set() + client.start() try: # stopping both nodes at the same time # else the test seems flaky when on CI hosts diff --git a/pyproject.toml b/pyproject.toml index b7d67f73..39d7d62f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -114,11 +114,11 @@ module = [ 'kazoo.testing.common', 'kazoo.testing.harness', 'kazoo.tests.conftest', - 'kazoo.tests.test__connection', 'kazoo.tests.test_barrier', 'kazoo.tests.test_build', 'kazoo.tests.test_cache', 'kazoo.tests.test_client', + 'kazoo.tests.test_connection', 'kazoo.tests.test_counter', 'kazoo.tests.test_election', 'kazoo.tests.test_eventlet_handler', diff --git a/tox.ini b/tox.ini index 6fd246f3..664c5b3c 100644 --- a/tox.ini +++ b/tox.ini @@ -36,7 +36,7 @@ allowlist_externals = commands = sasl: {toxinidir}/init_krb5.sh {envtmpdir}/kerberos \ {toxinidir}/ensure-zookeeper-env.sh \ - pytest {posargs: -ra -v --cov-report=xml --cov=kazoo kazoo/tests} + pytest {posargs: -ra -v --cov-report=xml --cov=kazoo kazoo/tests/test_connection.py} [testenv:build]