Skip to content

Commit 30f7be4

Browse files
authored
Merge pull request #3620 from mulkieran/use-retry
Use tenacity for retries in Python tests
2 parents daaa3d5 + 5cf3f4f commit 30f7be4

4 files changed

Lines changed: 20 additions & 19 deletions

File tree

.github/workflows/support.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
python3-psutil
4747
python3-pyudev
4848
python3-semantic_version
49+
python3-tenacity
4950
task: PYTHONPATH=./src make -f Makefile lint
5051
working-directory: ./tests/client-dbus
5152
- dependencies: black python3-isort

.github/workflows/weekly.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
python3-psutil
2525
python3-pyudev
2626
python3-semantic_version
27+
python3-tenacity
2728
task: PYTHONPATH=./src make -f Makefile lint
2829
working-directory: ./tests/client-dbus
2930
- dependencies: black python3-isort

tests-fmf/python.fmf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require:
1010
- python3-dbus-python-client-gen
1111
- python3-psutil
1212
- python3-pyudev
13+
- python3-tenacity
1314

1415
environment:
1516
TANG_URL: localhost

tests/client-dbus/tests/udev/_utils.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import dbus
3232
import psutil
3333
import pyudev
34+
from tenacity import Retrying, retry_if_exception_type, stop_after_delay, wait_fixed
3435

3536
# isort: LOCAL
3637
from stratisd_client_dbus import (
@@ -341,27 +342,24 @@ def start_service(self):
341342
text=True,
342343
)
343344

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

357-
time.sleep(1)
358-
if service.poll() is not None:
357+
with attempt:
358+
get_object(TOP_OBJECT)
359+
except dbus.exceptions.DBusException as err:
359360
raise RuntimeError(
360-
f"Daemon unexpectedly exited with exit code {service.returncode}"
361-
)
362-
363-
if not dbus_interface_present:
364-
raise RuntimeError("No D-Bus interface for stratisd found")
361+
"No D-Bus interface for stratisd found although stratisd appears to be running"
362+
) from err
365363

366364
self._service = service # pylint: disable=attribute-defined-outside-init
367365
return self

0 commit comments

Comments
 (0)