Skip to content

Commit

Permalink
fix(tests): making test_read_only test less flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenSorriaux committed Mar 24, 2023
1 parent 33c348b commit 8a21392
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit 8a21392

Please sign in to comment.