From f0e98f1f69b18435bf511355f2b4d79ca20658a9 Mon Sep 17 00:00:00 2001 From: Denis Rystsov Date: Sat, 18 Jun 2022 22:06:08 -0700 Subject: [PATCH] ducky: make wait_until faster temporary adding a faster version of wait_until before the ducktape repo is updated --- tests/rptest/services/admin.py | 1 - tests/rptest/tests/raft_availability_test.py | 2 +- tests/rptest/util.py | 28 +++++++++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/tests/rptest/services/admin.py b/tests/rptest/services/admin.py index eba3d5ff3df6f..51b20ff2d42cb 100644 --- a/tests/rptest/services/admin.py +++ b/tests/rptest/services/admin.py @@ -14,7 +14,6 @@ from requests.adapters import HTTPAdapter from requests.exceptions import RequestException from requests.packages.urllib3.util.retry import Retry -from ducktape.utils.util import wait_until from ducktape.cluster.cluster import ClusterNode from typing import Optional, Callable, NamedTuple from rptest.util import wait_until_result diff --git a/tests/rptest/tests/raft_availability_test.py b/tests/rptest/tests/raft_availability_test.py index 88607f3c8df89..fc7c05a221428 100644 --- a/tests/rptest/tests/raft_availability_test.py +++ b/tests/rptest/tests/raft_availability_test.py @@ -16,7 +16,7 @@ import requests from ducktape.mark import parametrize -from ducktape.utils.util import wait_until +from rptest.util import wait_until from rptest.clients.kafka_cat import KafkaCat from rptest.clients.rpk import RpkTool, RpkException diff --git a/tests/rptest/util.py b/tests/rptest/util.py index e7b22ba055ba3..0049cda0cc86c 100644 --- a/tests/rptest/util.py +++ b/tests/rptest/util.py @@ -11,8 +11,9 @@ from contextlib import contextmanager from requests.exceptions import HTTPError -from ducktape.utils.util import wait_until from rptest.clients.kafka_cli_tools import KafkaCliTools +from ducktape.errors import TimeoutError +import time class Scale: @@ -47,6 +48,31 @@ def release(self): return self._scale == Scale.RELEASE +def wait_until(condition, + timeout_sec, + backoff_sec=.1, + err_msg="", + retry_on_exc=False): + start = time.time() + stop = start + timeout_sec + last_exception = None + while time.time() < stop: + try: + if condition(): + return + else: + last_exception = None + except BaseException as e: + last_exception = e + if not retry_on_exc: + raise e + time.sleep(backoff_sec) + + # it is safe to call Exception from None - will be just treated as a normal exception + raise TimeoutError( + err_msg() if callable(err_msg) else err_msg) from last_exception + + def wait_until_result(condition, *args, **kwargs): """ a near drop-in replacement for ducktape's wait_util except that when