From f1859feb162aef7104f423c687415368f28ff408 Mon Sep 17 00:00:00 2001 From: Iurii Pliner Date: Wed, 8 Jan 2025 19:26:33 +0000 Subject: [PATCH] Fix review comments --- aio_request/deadline_provider.py | 16 ++++++++-------- tests/test_deadline_provider.py | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/aio_request/deadline_provider.py b/aio_request/deadline_provider.py index ab6c499..c21e6a6 100644 --- a/aio_request/deadline_provider.py +++ b/aio_request/deadline_provider.py @@ -5,7 +5,7 @@ DeadlineProvider = Callable[[Deadline, int, int], Deadline] -def split_deadline_between_attempts(*, split_factor: int | None = None) -> DeadlineProvider: +def split_deadline_between_attempts(*, attempts_count_to_split: int | None = None) -> DeadlineProvider: """ Split deadline between attempts. @@ -18,19 +18,19 @@ def split_deadline_between_attempts(*, split_factor: int | None = None) -> Deadl the last one has received the remaining 8 seconds due to redistribution. """ - if split_factor is not None and split_factor < 2: - raise ValueError("split_factor should be greater or equal to 2") + if attempts_count_to_split is not None and attempts_count_to_split < 2: + raise ValueError("attempts_count_to_split should be greater or equal to 2") def __provider(deadline: Deadline, attempt: int, attempts_count: int) -> Deadline: if deadline.expired: return deadline - if split_factor is None: - effective_split_factor = attempts_count - attempt + if attempts_count_to_split is None: + effective_attempts_left = attempts_count - attempt else: - effective_split_factor = min(split_factor, attempts_count) - attempt - if effective_split_factor <= 1: + effective_attempts_left = min(attempts_count_to_split, attempts_count) - attempt + if effective_attempts_left <= 1: return deadline - return deadline / effective_split_factor + return deadline / effective_attempts_left return __provider diff --git a/tests/test_deadline_provider.py b/tests/test_deadline_provider.py index 9fcefbd..01de8c0 100644 --- a/tests/test_deadline_provider.py +++ b/tests/test_deadline_provider.py @@ -21,7 +21,7 @@ async def test_split_deadline_between_attempt(): async def test_split_deadline_between_attempt_with_split_factor(): - provider = aio_request.split_deadline_between_attempts(split_factor=2) + provider = aio_request.split_deadline_between_attempts(attempts_count_to_split=2) deadline = aio_request.Deadline.from_timeout(1) attempt_deadline = provider(deadline, 0, 3) @@ -56,7 +56,7 @@ async def test_split_deadline_between_attempts_fast_attempt_failure(): async def test_split_deadline_between_attempts_fast_attempt_failure_with_split_factor(): - provider = aio_request.split_deadline_between_attempts(split_factor=2) + provider = aio_request.split_deadline_between_attempts(attempts_count_to_split=2) deadline = aio_request.Deadline.from_timeout(1) attempt_deadline = provider(deadline, 0, 3)