Skip to content

Commit

Permalink
XFAIL when iteration takes much longer than retry_period
Browse files Browse the repository at this point in the history
  • Loading branch information
woutdenolf committed Aug 13, 2024
1 parent aa1f743 commit 08856bb
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/silx/utils/test/test_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import sys
import time
import tempfile
import pytest

from .. import retry

Expand Down Expand Up @@ -212,26 +213,39 @@ def method():
yield from range(3)

def test_retry_iter_reset(self):
"""Test would fail when the timer does not get reset after every iteration"""
failure_t0 = None
failure_count = 0
retry_period = 0.2
failure_duration = 0.6
retry_period = 0.1
failure_duration = 0.7
nretry_offset = 10

nfailures = int(failure_duration/retry_period + 0.5)
nfailures = int(failure_duration / retry_period + 0.5)
retry_timeout = failure_duration + retry_period
xfail_timeout = failure_duration + retry_period * 0.5

@retry.retry(retry_period=retry_period, retry_timeout=retry_timeout)
def iter_silx(start_index=0):
nonlocal failure_count
def iter_with_failure(start_index=0):
nonlocal failure_count, failure_t0

# This takes `10 * retry_period` seconds
# This takes `nretry_offset * retry_period` seconds
if start_index == 0:
for i in range(10):
for i in range(nretry_offset):
time.sleep(retry_period)
yield i
failure_t0 = time.time()

# This will fail for slightly longer than `failure_duration` seconds
if failure_count <= nfailures:
failure_count += 1
if failure_count > 1:
iter_time = (time.time() - failure_t0) / (failure_count - 1)
if (iter_time * nfailures) >= xfail_timeout:
pytest.xfail("iteration takes much longer than retry_period")
raise retry.RetryError()

assert list(iter_silx()) == list(range(10))
yield nretry_offset

yielded = list(iter_with_failure())
expected = list(range(nretry_offset + 1))
assert yielded == expected

0 comments on commit 08856bb

Please sign in to comment.