Skip to content

Commit

Permalink
ducky: make wait_until faster
Browse files Browse the repository at this point in the history
temporary adding a faster version of wait_until before the
ducktape repo is updated
  • Loading branch information
rystsov committed Jun 23, 2022
1 parent 9ccbfce commit b4a5fb2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
1 change: 0 additions & 1 deletion tests/rptest/services/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/rptest/tests/raft_availability_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 27 additions & 1 deletion tests/rptest/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b4a5fb2

Please sign in to comment.