Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tenacity for retries in Python tests #3620

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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