|
21 | 21 | "ZOOKEEPER_OBSERVER_START_ID": -1,
|
22 | 22 | "ZOOKEEPER_LOCAL_SESSION_RO": "false",
|
23 | 23 | }
|
| 24 | +MAX_INIT_TRIES = 5 |
24 | 25 |
|
25 | 26 |
|
26 | 27 | def get_global_cluster():
|
@@ -208,8 +209,29 @@ def setup_zookeeper(self, **client_options):
|
208 | 209 | self.cluster.start()
|
209 | 210 | namespace = "/kazootests" + uuid.uuid4().hex
|
210 | 211 | self.hosts = self.servers + namespace
|
211 |
| - if "timeout" not in client_options: |
212 |
| - client_options["timeout"] = self.DEFAULT_CLIENT_TIMEOUT |
| 212 | + |
| 213 | + tries = 0 |
| 214 | + while True: |
| 215 | + try: |
| 216 | + client_cluster_health = self._get_client() |
| 217 | + client_cluster_health.start() |
| 218 | + client_cluster_health.ensure_path("/") |
| 219 | + client_cluster_health.stop() |
| 220 | + self.log(logging.INFO, "cluster looks ready to go") |
| 221 | + break |
| 222 | + except Exception: |
| 223 | + tries += 1 |
| 224 | + if tries >= MAX_INIT_TRIES: |
| 225 | + raise |
| 226 | + if tries > 0 and tries % 2 == 0: |
| 227 | + self.log( |
| 228 | + logging.WARNING, |
| 229 | + "nuking current cluster and making another one", |
| 230 | + ) |
| 231 | + self.cluster.terminate() |
| 232 | + self.cluster.start() |
| 233 | + continue |
| 234 | + |
213 | 235 | self.client = self._get_client(**client_options)
|
214 | 236 | self.client.start()
|
215 | 237 | self.client.ensure_path("/")
|
@@ -259,3 +281,9 @@ def setUp(self):
|
259 | 281 |
|
260 | 282 | def tearDown(self):
|
261 | 283 | self.teardown_zookeeper()
|
| 284 | + |
| 285 | + @classmethod |
| 286 | + def tearDownClass(cls): |
| 287 | + cluster = get_global_cluster() |
| 288 | + if cluster is not None: |
| 289 | + cluster.terminate() |
0 commit comments