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

Rerun time based retry tests to avoid flaky failures #12869

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Empty file.
12 changes: 7 additions & 5 deletions tests/unit/test_utils_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,24 @@ def _raise_error() -> NoReturn:
@pytest.mark.skipif(
sys.platform == "win32", reason="Too flaky on Windows due to poor timer resolution"
)
@pytest.mark.flaky(reruns=3, reruns_delay=1)
@pytest.mark.parametrize("wait_duration", [0.015, 0.045, 0.15])
def test_retry_wait(wait_duration: float) -> None:
function, timestamps = create_timestamped_callable()
# Only the first retry will be scheduled before the time limit is exceeded.
wrapped = retry(wait=wait_duration, stop_after_delay=0.01)(function)
wrapped = retry(wait=wait_duration, stop_after_delay=0.1)(function)
start_time = perf_counter()
with pytest.raises(RuntimeError):
wrapped()
assert len(timestamps) == 2
# Add a margin of 10% to permit for unavoidable variation.
assert len(timestamps) >= 2
# Just check the first retry, with a margin of 10% to permit for
# unavoidable variation.
assert timestamps[1] - start_time >= (wait_duration * 0.9)


@pytest.mark.skipif(
sys.platform == "win32", reason="Too flaky on Windows due to poor timer resolution"
)
@pytest.mark.flaky(reruns=3, reruns_delay=1)
@pytest.mark.parametrize(
"call_duration, max_allowed_calls", [(0.01, 11), (0.04, 3), (0.15, 1)]
)
Expand All @@ -113,7 +115,7 @@ class MyClass:
def __init__(self) -> None:
self.calls = 0

@retry(wait=0, stop_after_delay=0.01)
@retry(wait=0, stop_after_delay=3)
def method(self, string: str) -> str:
self.calls += 1
if self.calls >= 5:
Expand Down
Loading