Skip to content

Commit

Permalink
Merge pull request #3620 from mulkieran/use-retry
Browse files Browse the repository at this point in the history
Use tenacity for retries in Python tests
  • Loading branch information
mulkieran authored Sep 13, 2024
2 parents daaa3d5 + 5cf3f4f commit 30f7be4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
1 change: 1 addition & 0 deletions .github/workflows/support.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
python3-psutil
python3-pyudev
python3-semantic_version
python3-tenacity
task: PYTHONPATH=./src make -f Makefile lint
working-directory: ./tests/client-dbus
- dependencies: black python3-isort
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
python3-psutil
python3-pyudev
python3-semantic_version
python3-tenacity
task: PYTHONPATH=./src make -f Makefile lint
working-directory: ./tests/client-dbus
- dependencies: black python3-isort
Expand Down
1 change: 1 addition & 0 deletions tests-fmf/python.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require:
- python3-dbus-python-client-gen
- python3-psutil
- python3-pyudev
- python3-tenacity

environment:
TANG_URL: localhost
Expand Down
36 changes: 17 additions & 19 deletions tests/client-dbus/tests/udev/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import dbus
import psutil
import pyudev
from tenacity import Retrying, retry_if_exception_type, stop_after_delay, wait_fixed

# isort: LOCAL
from stratisd_client_dbus import (
Expand Down Expand Up @@ -341,27 +342,24 @@ def start_service(self):
text=True,
)

dbus_interface_present = False
limit = time.time() + 120.0
while (
time.time() <= limit
and not dbus_interface_present
and service.poll() is None
):
try:
get_object(TOP_OBJECT)
dbus_interface_present = True
except dbus.exceptions.DBusException:
time.sleep(0.5)
try:
for attempt in Retrying(
retry=(retry_if_exception_type(dbus.exceptions.DBusException)),
stop=stop_after_delay(120),
wait=wait_fixed(0.5),
reraise=True,
):
if service.poll() is not None:
raise RuntimeError(
f"Daemon unexpectedly exited with exit code {service.returncode}"
)

time.sleep(1)
if service.poll() is not None:
with attempt:
get_object(TOP_OBJECT)
except dbus.exceptions.DBusException as err:
raise RuntimeError(
f"Daemon unexpectedly exited with exit code {service.returncode}"
)

if not dbus_interface_present:
raise RuntimeError("No D-Bus interface for stratisd found")
"No D-Bus interface for stratisd found although stratisd appears to be running"
) from err

self._service = service # pylint: disable=attribute-defined-outside-init
return self
Expand Down

0 comments on commit 30f7be4

Please sign in to comment.