Skip to content

Commit 8a21392

Browse files
fix(tests): making test_read_only test less flaky
1 parent 33c348b commit 8a21392

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

kazoo/tests/test__connection.py renamed to kazoo/tests/test_connection.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def back(state):
258258
class TestReadOnlyMode(KazooTestCase):
259259
def setUp(self):
260260
os.environ["ZOOKEEPER_LOCAL_SESSION_RO"] = "true"
261-
self.setup_zookeeper(read_only=True)
261+
self.setup_zookeeper()
262262
skip = False
263263
if CI_ZK_VERSION and CI_ZK_VERSION < (3, 4):
264264
skip = True
@@ -278,8 +278,13 @@ def tearDown(self):
278278
def test_read_only(self):
279279
from kazoo.exceptions import NotReadOnlyCallError
280280
from kazoo.protocol.states import KeeperState
281+
from kazoo.retry import KazooRetry
281282

282-
client = self.client
283+
conn_retry = KazooRetry(max_tries=10, delay=0.2)
284+
client = self._get_client(
285+
connection_retry=conn_retry,
286+
read_only=True
287+
)
283288
states = []
284289
ev = threading.Event()
285290

@@ -289,6 +294,7 @@ def listen(state):
289294
if client.client_state == KeeperState.CONNECTED_RO:
290295
ev.set()
291296

297+
client.start()
292298
try:
293299
# stopping both nodes at the same time
294300
# else the test seems flaky when on CI hosts

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ module = [
114114
'kazoo.testing.common',
115115
'kazoo.testing.harness',
116116
'kazoo.tests.conftest',
117-
'kazoo.tests.test__connection',
118117
'kazoo.tests.test_barrier',
119118
'kazoo.tests.test_build',
120119
'kazoo.tests.test_cache',
121120
'kazoo.tests.test_client',
121+
'kazoo.tests.test_connection',
122122
'kazoo.tests.test_counter',
123123
'kazoo.tests.test_election',
124124
'kazoo.tests.test_eventlet_handler',

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ allowlist_externals =
3636
commands =
3737
sasl: {toxinidir}/init_krb5.sh {envtmpdir}/kerberos \
3838
{toxinidir}/ensure-zookeeper-env.sh \
39-
pytest {posargs: -ra -v --cov-report=xml --cov=kazoo kazoo/tests}
39+
pytest {posargs: -ra -v --cov-report=xml --cov=kazoo kazoo/tests/test_connection.py}
4040

4141
[testenv:build]
4242

0 commit comments

Comments
 (0)