FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Retry: sleep_for_retry uses max(wait, delay_max) — inflates small Retry-After to delay_max (60s floor) (#860) by peco-engineer-bot[bot] · Pull Request #868 · databricks/databricks-sql-python · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 0 additions & 1 deletion src/databricks/sql/auth/retry.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ def sleep_for_retry(self, response: BaseHTTPResponse) -> bool:
else:
proposed_wait = self.get_backoff_time()

proposed_wait = max(proposed_wait, self.delay_max)
self.check_proposed_wait(proposed_wait)
logger.debug(f"Retrying after {proposed_wait} seconds")
time.sleep(proposed_wait)
Expand Down
35 changes: 25 additions & 10 deletions tests/unit/test_retry.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,32 @@ def test_sleep__no_retry_after(self, t_mock, retry_policy, error_history):
retry_policy.history = [error_history, error_history]
retry_policy.sleep(HTTPResponse(status=503))

expected_backoff_time = max(
self.calculate_backoff_time(
0, retry_policy.delay_min, retry_policy.delay_max
),
retry_policy.delay_max,
expected_backoff_time = self.calculate_backoff_time(
0, retry_policy.delay_min, retry_policy.delay_max
)
t_mock.assert_called_with(expected_backoff_time)

@patch("time.sleep")
def test_sleep__short_retry_after_is_not_inflated(self, t_mock, retry_policy):
# A small server Retry-After must be honored as-is (delay_max is a
# ceiling, not a floor). delay_max defaults to 30 in these fixtures.
retry_policy._retry_start_time = time.time()
retry_policy.history = []
retry_policy.sleep(HTTPResponse(status=503, headers={"Retry-After": "2"}))

t_mock.assert_called_with(2)

@patch("time.sleep")
def test_sleep__large_retry_after_is_honored_as_is(self, t_mock, retry_policy):
# A server-returned Retry-After is the source of truth and must be
# honored as-is; delay_max does not cap it. delay_max defaults to 30 in
# these fixtures, so 120 would be clamped if the ceiling still applied.
retry_policy._retry_start_time = time.time()
retry_policy.history = []
retry_policy.sleep(HTTPResponse(status=503, headers={"Retry-After": "120"}))

t_mock.assert_called_with(120)

@patch("time.sleep")
def test_sleep__no_retry_after_header__multiple_retries(self, t_mock, retry_policy):
num_attempts = retry_policy.stop_after_attempts_count
Expand All @@ -62,11 +80,8 @@ def test_sleep__no_retry_after_header__multiple_retries(self, t_mock, retry_poli
expected_backoff_times = []
for attempt in range(num_attempts):
expected_backoff_times.append(
max(
self.calculate_backoff_time(
attempt, retry_policy.delay_min, retry_policy.delay_max
),
retry_policy.delay_max,
self.calculate_backoff_time(
attempt, retry_policy.delay_min, retry_policy.delay_max
)
)

Expand Down
Loading

Back | FazBrowse Home | New Git URL