Skip to content

Commit d889657

Browse files
Retry transient Vuforia setup failures (#3222)
1 parent 225ea8d commit d889657

4 files changed

Lines changed: 13 additions & 9 deletions

File tree

conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
PythonCodeBlockParser,
1111
)
1212

13-
from tests.mock_vws.utils.retries import RETRY_EXCEPTIONS
13+
from tests.mock_vws.utils.retries import TRANSIENT_VWS_EXCEPTIONS
1414

1515
pytest_collect_file = Sybil(
1616
parsers=[
@@ -29,4 +29,4 @@ def pytest_set_filtered_exceptions() -> tuple[type[Exception], ...]:
2929
This is for ``pytest-retry``.
3030
The configuration for retries is in ``pyproject.toml``.
3131
"""
32-
return RETRY_EXCEPTIONS
32+
return TRANSIENT_VWS_EXCEPTIONS

tests/mock_vws/fixtures/prepared_requests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
from mock_vws.database import CloudDatabase
1818
from tests.mock_vws.fixtures.credentials import VuMarkCloudDatabase
1919
from tests.mock_vws.utils import Endpoint
20-
from tests.mock_vws.utils.retries import RETRY_ON_TOO_MANY_REQUESTS
20+
from tests.mock_vws.utils.retries import RETRY_ON_TRANSIENT_VWS_FAILURE
2121

2222
VWS_HOST = "https://vws.vuforia.com"
2323
VWQ_HOST = "https://cloudreco.vuforia.com"
2424

2525

2626
@beartype
27-
@RETRY_ON_TOO_MANY_REQUESTS
27+
@RETRY_ON_TRANSIENT_VWS_FAILURE
2828
def _wait_for_target_processed(*, vws_client: VWS, target_id: str) -> None:
2929
"""Wait for a target to be processed.
3030

tests/mock_vws/fixtures/vuforia_backends.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
InactiveVuMarkCloudDatabase,
2727
VuMarkCloudDatabase,
2828
)
29-
from tests.mock_vws.utils.retries import RETRY_ON_TOO_MANY_REQUESTS
29+
from tests.mock_vws.utils.retries import RETRY_ON_TRANSIENT_VWS_FAILURE
3030

3131
LOGGER = logging.getLogger(name=__name__)
3232
LOGGER.setLevel(level=logging.DEBUG)
3333

3434

3535
@beartype
36-
@RETRY_ON_TOO_MANY_REQUESTS
36+
@RETRY_ON_TRANSIENT_VWS_FAILURE
3737
def _delete_all_targets(*, database_keys: CloudDatabase) -> None:
3838
"""Delete all targets.
3939

tests/mock_vws/utils/retries.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
"""Helpers for retrying requests to VWS."""
22

3+
from requests.exceptions import Timeout as RequestsTimeout
34
from tenacity import retry
45
from tenacity.retry import retry_if_exception_type
6+
from tenacity.stop import stop_after_attempt
57
from tenacity.wait import wait_fixed
68
from vws.exceptions.custom_exceptions import ServerError
79
from vws.exceptions.vws_exceptions import (
810
TooManyRequestsError,
911
)
1012

11-
RETRY_EXCEPTIONS = (TooManyRequestsError, ServerError)
13+
TRANSIENT_VWS_EXCEPTIONS = (TooManyRequestsError, ServerError, RequestsTimeout)
14+
TRANSIENT_VWS_RETRY_ATTEMPTS = 10
1215

1316
# We rely on pytest-retry for exceptions *during* tests.
1417
# We use tenacity for exceptions *before* tests.
1518
# See https://github.com/str0zzapreti/pytest-retry/issues/33.
16-
RETRY_ON_TOO_MANY_REQUESTS = retry(
17-
retry=retry_if_exception_type(exception_types=RETRY_EXCEPTIONS),
19+
RETRY_ON_TRANSIENT_VWS_FAILURE = retry(
20+
retry=retry_if_exception_type(exception_types=TRANSIENT_VWS_EXCEPTIONS),
21+
stop=stop_after_attempt(max_attempt_number=TRANSIENT_VWS_RETRY_ATTEMPTS),
1822
wait=wait_fixed(wait=10),
1923
reraise=True,
2024
)

0 commit comments

Comments
 (0)