Skip to content

Commit e7a1efb

Browse files
authored
✅ Is3569/flaky public api test (ITISFoundation#3634)
1 parent 4b2db6c commit e7a1efb

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

tests/public-api/test_solvers_jobs_api.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# pylint:disable=unused-argument
99
# pylint:disable=redefined-outer-name
1010

11+
import logging
1112
import time
1213
from operator import attrgetter
1314
from pathlib import Path
@@ -16,14 +17,23 @@
1617
from zipfile import ZipFile
1718

1819
import osparc
20+
import osparc.exceptions
1921
import pytest
2022
from osparc import FilesApi, SolversApi
2123
from osparc.models import File, Job, JobInputs, JobOutputs, JobStatus, Solver
24+
from tenacity import Retrying, TryAgain
25+
from tenacity.after import after_log
26+
from tenacity.retry import retry_if_exception_type
27+
from tenacity.stop import stop_after_attempt
28+
from tenacity.wait import wait_fixed
2229

2330
OSPARC_CLIENT_VERSION = tuple(map(int, osparc.__version__.split(".")))
2431
assert OSPARC_CLIENT_VERSION >= (0, 4, 3)
2532

2633

34+
logger = logging.getLogger(__name__)
35+
36+
2737
@pytest.fixture(scope="module")
2838
def sleeper_solver(
2939
solvers_api: SolversApi,
@@ -169,6 +179,17 @@ def test_create_job(
169179
assert job.id != job2.id
170180

171181

182+
_RETRY_POLICY_IF_LOGFILE_404_NOT_FOUND = dict(
183+
# NOTE: Only 404s https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404
184+
# are retried, the rest are failures
185+
retry=retry_if_exception_type(TryAgain),
186+
wait=wait_fixed(1),
187+
stop=stop_after_attempt(3),
188+
after=after_log(logger, logging.WARNING),
189+
reraise=True,
190+
)
191+
192+
172193
@pytest.mark.parametrize("expected_outcome", ("SUCCESS", "FAILED"))
173194
def test_run_job(
174195
uploaded_input_file: File,
@@ -264,9 +285,22 @@ def test_run_job(
264285
# download log (Added in on API version 0.4.0 / client version 0.5.0 )
265286
if OSPARC_CLIENT_VERSION >= (0, 5, 0):
266287
print("Testing output logfile ...")
267-
logfile: str = solvers_api.get_job_output_logfile(
268-
solver.id, solver.version, job.id
269-
)
288+
289+
# NOTE: https://github.com/itisfoundation/osparc-simcore/issues/3569 shows
290+
# that this test might not have the logs ready in time and returns a 404 (not found)
291+
# for that reason we do a few retries before giving up
292+
for attempt in Retrying(_RETRY_POLICY_IF_LOGFILE_404_NOT_FOUND):
293+
with attempt:
294+
try:
295+
logfile: str = solvers_api.get_job_output_logfile(
296+
solver.id, solver.version, job.id
297+
)
298+
except osparc.exceptions.ApiException as err:
299+
if err.status == 404:
300+
raise TryAgain(
301+
f"get_job_output_logfile failed with {err}"
302+
) from err
303+
270304
zip_path = Path(logfile)
271305
print(
272306
f"{zip_path=}",

0 commit comments

Comments
 (0)