From 707c7d1305d7592981720e5f38738d998031708b Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Thu, 12 Sep 2024 17:46:47 -0700 Subject: [PATCH] Update more ZooKeeperClient timeouts in tests A recent change updated some uses of the ZooKeeperClient to use a consistent, and more generous, timeout, in order to reduce the number of incidents of racy test failures. There are several more places where we construct a client object which could benefit from the same change. This commit updates the remaining instances. Change-Id: Ia7b7fc491779145fdf71449e4caa6c331553a937 --- tests/unit/test_database.py | 8 ++++++-- tests/unit/test_event_queues.py | 17 +++++++++++++---- tests/unit/test_model_upgrade.py | 5 ++++- tests/unit/test_nodepool.py | 11 +++++++++-- tests/unit/test_zk.py | 6 +++++- 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/tests/unit/test_database.py b/tests/unit/test_database.py index e07643cbd1..cffdf9f1b6 100644 --- a/tests/unit/test_database.py +++ b/tests/unit/test_database.py @@ -20,7 +20,10 @@ import subprocess from zuul.driver.sql import SQLDriver from zuul.zk import ZooKeeperClient from tests.base import ( - BaseTestCase, MySQLSchemaFixture, PostgresqlSchemaFixture + BaseTestCase, + MySQLSchemaFixture, + PostgresqlSchemaFixture, + ZOOKEEPER_SESSION_TIMEOUT, ) import sqlalchemy @@ -36,7 +39,8 @@ class DBBaseTestCase(BaseTestCase): self.zk_chroot_fixture.zk_hosts, tls_cert=self.zk_chroot_fixture.zookeeper_cert, tls_key=self.zk_chroot_fixture.zookeeper_key, - tls_ca=self.zk_chroot_fixture.zookeeper_ca + tls_ca=self.zk_chroot_fixture.zookeeper_ca, + timeout=ZOOKEEPER_SESSION_TIMEOUT, ) self.addCleanup(self.zk_client.disconnect) self.zk_client.connect() diff --git a/tests/unit/test_event_queues.py b/tests/unit/test_event_queues.py index 47346cba5d..e9a156e2d6 100644 --- a/tests/unit/test_event_queues.py +++ b/tests/unit/test_event_queues.py @@ -26,7 +26,11 @@ from zuul.zk.components import ( ComponentRegistry, COMPONENT_REGISTRY ) -from tests.base import BaseTestCase, iterate_timeout +from tests.base import ( + BaseTestCase, + iterate_timeout, + ZOOKEEPER_SESSION_TIMEOUT, +) class EventQueueBaseTestCase(BaseTestCase): @@ -39,7 +43,8 @@ class EventQueueBaseTestCase(BaseTestCase): self.zk_chroot_fixture.zk_hosts, tls_cert=self.zk_chroot_fixture.zookeeper_cert, tls_key=self.zk_chroot_fixture.zookeeper_key, - tls_ca=self.zk_chroot_fixture.zookeeper_ca + tls_ca=self.zk_chroot_fixture.zookeeper_ca, + timeout=ZOOKEEPER_SESSION_TIMEOUT, ) self.addCleanup(self.zk_client.disconnect) self.zk_client.connect() @@ -461,7 +466,9 @@ class TestManagementEventQueue(EventQueueBaseTestCase): self.zk_chroot_fixture.zk_hosts, tls_cert=self.zk_chroot_fixture.zookeeper_cert, tls_key=self.zk_chroot_fixture.zookeeper_key, - tls_ca=self.zk_chroot_fixture.zookeeper_ca) + tls_ca=self.zk_chroot_fixture.zookeeper_ca, + timeout=ZOOKEEPER_SESSION_TIMEOUT, + ) self.addCleanup(external_client.disconnect) external_client.connect() @@ -502,7 +509,9 @@ class TestManagementEventQueue(EventQueueBaseTestCase): self.zk_chroot_fixture.zk_hosts, tls_cert=self.zk_chroot_fixture.zookeeper_cert, tls_key=self.zk_chroot_fixture.zookeeper_key, - tls_ca=self.zk_chroot_fixture.zookeeper_ca) + tls_ca=self.zk_chroot_fixture.zookeeper_ca, + timeout=ZOOKEEPER_SESSION_TIMEOUT, + ) self.addCleanup(external_client.disconnect) external_client.connect() diff --git a/tests/unit/test_model_upgrade.py b/tests/unit/test_model_upgrade.py index 49009d0081..08e8a68686 100644 --- a/tests/unit/test_model_upgrade.py +++ b/tests/unit/test_model_upgrade.py @@ -25,6 +25,7 @@ from tests.base import ( simple_layout, iterate_timeout, model_version, + ZOOKEEPER_SESSION_TIMEOUT, ) from zuul.zk import ZooKeeperClient from zuul.zk.branch_cache import BranchCache, BranchFlag @@ -215,7 +216,9 @@ class TestBranchCacheUpgrade(BaseTestCase): self.zk_chroot_fixture.zk_hosts, tls_cert=self.zk_chroot_fixture.zookeeper_cert, tls_key=self.zk_chroot_fixture.zookeeper_key, - tls_ca=self.zk_chroot_fixture.zookeeper_ca) + tls_ca=self.zk_chroot_fixture.zookeeper_ca, + timeout=ZOOKEEPER_SESSION_TIMEOUT, + ) self.addCleanup(self.zk_client.disconnect) self.zk_client.connect() self.model_test_component_info = SchedulerComponent( diff --git a/tests/unit/test_nodepool.py b/tests/unit/test_nodepool.py index d8e5f7b279..5326ab1df9 100644 --- a/tests/unit/test_nodepool.py +++ b/tests/unit/test_nodepool.py @@ -17,7 +17,12 @@ import uuid from zuul import model import zuul.nodepool -from tests.base import BaseTestCase, FakeNodepool, iterate_timeout +from tests.base import ( + BaseTestCase, + FakeNodepool, + iterate_timeout, + ZOOKEEPER_SESSION_TIMEOUT, +) from zuul.zk import ZooKeeperClient from zuul.zk.nodepool import ZooKeeperNodepool from zuul.zk.components import COMPONENT_REGISTRY @@ -58,7 +63,9 @@ class TestNodepoolBase(BaseTestCase): self.zk_chroot_fixture.zk_hosts, tls_cert=self.zk_chroot_fixture.zookeeper_cert, tls_key=self.zk_chroot_fixture.zookeeper_key, - tls_ca=self.zk_chroot_fixture.zookeeper_ca) + tls_ca=self.zk_chroot_fixture.zookeeper_ca, + timeout=ZOOKEEPER_SESSION_TIMEOUT, + ) self.zk_nodepool = ZooKeeperNodepool(self.zk_client) self.addCleanup(self.zk_client.disconnect) self.zk_client.connect() diff --git a/tests/unit/test_zk.py b/tests/unit/test_zk.py index 3eab7961f8..33d9103209 100644 --- a/tests/unit/test_zk.py +++ b/tests/unit/test_zk.py @@ -65,6 +65,7 @@ from tests.base import ( HoldableMergerApi, iterate_timeout, model_version, + ZOOKEEPER_SESSION_TIMEOUT, ) from zuul.zk.zkobject import ( ShardedZKObject, PolymorphicZKObjectMixin, ZKObject, ZKContext @@ -85,7 +86,9 @@ class ZooKeeperBaseTestCase(BaseTestCase): self.zk_chroot_fixture.zk_hosts, tls_cert=self.zk_chroot_fixture.zookeeper_cert, tls_key=self.zk_chroot_fixture.zookeeper_key, - tls_ca=self.zk_chroot_fixture.zookeeper_ca) + tls_ca=self.zk_chroot_fixture.zookeeper_ca, + timeout=ZOOKEEPER_SESSION_TIMEOUT, + ) self.addCleanup(self.zk_client.disconnect) self.zk_client.connect() self.setupModelPin() @@ -429,6 +432,7 @@ class TestComponentRegistry(ZooKeeperBaseTestCase): tls_cert=self.zk_chroot_fixture.zookeeper_cert, tls_key=self.zk_chroot_fixture.zookeeper_key, tls_ca=self.zk_chroot_fixture.zookeeper_ca, + timeout=ZOOKEEPER_SESSION_TIMEOUT, ) self.addCleanup(self.second_zk_client.disconnect) self.second_zk_client.connect()