Skip to content

Commit

Permalink
Add tests for odd times encountered
Browse files Browse the repository at this point in the history
  • Loading branch information
yarikoptic committed Feb 3, 2025
1 parent 0fe489a commit b2736e4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions dandi/tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -1266,3 +1266,29 @@ def test__check_attempts_and_sleep_retries(status_code: int) -> None:
)
mock_sleep.assert_called_once()
assert mock_sleep.call_args.args[0] > 0

# shifted by 1 year! (too long)
response.headers["Retry-After"] = "Wed, 21 Oct 2016 07:28:00 GMT"
with mock.patch("time.sleep") as mock_sleep, mock.patch(
"dandi.utils.datetime"
) as mock_datetime:
mock_datetime.datetime.now.return_value = parsedate_to_datetime(
"Wed, 21 Oct 2015 07:28:00 GMT"
)
assert f(HTTPError(response=response), attempt=1, attempts_allowed=2) == 2
mock_sleep.assert_called_once()
# and we do sleep some time
assert mock_sleep.call_args.args[0] > 0

# in the past second (too quick)
response.headers["Retry-After"] = "Wed, 21 Oct 2015 07:27:59 GMT"
with mock.patch("time.sleep") as mock_sleep, mock.patch(
"dandi.utils.datetime"
) as mock_datetime:
mock_datetime.datetime.now.return_value = parsedate_to_datetime(
"Wed, 21 Oct 2015 07:28:00 GMT"
)
assert f(HTTPError(response=response), attempt=1, attempts_allowed=2) == 2
mock_sleep.assert_called_once()
# and we do not sleep really
assert not mock_sleep.call_args.args[0]

0 comments on commit b2736e4

Please sign in to comment.