diff options
author | Stephen Sorriaux <stephen.sorriaux@gmail.com> | 2023-04-10 16:26:41 -0400 |
---|---|---|
committer | Stephen Sorriaux <stephen.sorriaux@gmail.com> | 2023-04-24 14:04:44 -0400 |
commit | 6b40a43761f456efafa48a262be145fb6fc74fc9 (patch) | |
tree | 432c5563313a03b886b9d90c6c7aee1ab72dac7b | |
parent | ffa0ae9a06932166f088846584e9b675988e0f23 (diff) | |
download | kazoo-6b40a43761f456efafa48a262be145fb6fc74fc9.tar.gz |
fix(tests): `test_read_only` is not flaky anymore.
Fixed the `test_read_only` test based on what is done in the official Java client, we were missing some things and that led the test to fail from time to time (see comments in the code for full story).
Also renamed `test__connection.py` to `test_connection.py`, where it belongs.
-rw-r--r-- | kazoo/tests/test_connection.py (renamed from kazoo/tests/test__connection.py) | 21 | ||||
-rw-r--r-- | pyproject.toml | 2 |
2 files changed, 18 insertions, 5 deletions
diff --git a/kazoo/tests/test__connection.py b/kazoo/tests/test_connection.py index 80a777e..032b94b 100644 --- a/kazoo/tests/test__connection.py +++ b/kazoo/tests/test_connection.py @@ -18,8 +18,7 @@ from kazoo.protocol.serialization import ( from kazoo.protocol.states import KazooState from kazoo.protocol.connection import _CONNECTION_DROP from kazoo.testing import KazooTestCase -from kazoo.tests.util import wait -from kazoo.tests.util import CI_ZK_VERSION +from kazoo.tests.util import wait, CI_ZK_VERSION, CI class Delete(namedtuple("Delete", "path version")): @@ -258,7 +257,7 @@ class TestConnectionDrop(KazooTestCase): 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 @@ -279,7 +278,15 @@ class TestReadOnlyMode(KazooTestCase): from kazoo.exceptions import NotReadOnlyCallError from kazoo.protocol.states import KeeperState - client = self.client + if CI: + # force some wait to make sure the data produced during the + # `setUp()` step are replicaed to all zk members + # if not done the `get_children()` test may fail because the + # node does not exist on the node that we will keep alive + time.sleep(15) + # do not keep the client started in the `setUp` step alive + self.client.stop() + client = self._get_client(connection_retry=None, read_only=True) states = [] ev = threading.Event() @@ -289,6 +296,7 @@ class TestReadOnlyMode(KazooTestCase): 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 @@ -303,6 +311,11 @@ class TestReadOnlyMode(KazooTestCase): thread.start() for thread in zk_stop_threads: thread.join() + # stopping the client is *mandatory*, else the client might try to + # reconnect using a xid that the server may endlessly refuse + # restarting the client makes sure the xid gets reset + client.stop() + client.start() ev.wait(15) assert ev.is_set() assert client.client_state == KeeperState.CONNECTED_RO diff --git a/pyproject.toml b/pyproject.toml index b7d67f7..39d7d62 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', |