Skip to content

Commit

Permalink
Add one more test verifying that a configuring max_redirects doesn't
Browse files Browse the repository at this point in the history
prevent stop_after_attempts_count from being honoured.

Also clarifies the assertion for max_redirects limitations to make
sure that those MaxRetryError exceptions are because of redirects
specifically as opposed to exceeding some other limits (count, duration etc.)

Signed-off-by: Jesse Whitehouse <[email protected]>
  • Loading branch information
Jesse Whitehouse committed Oct 10, 2023
1 parent 07257ba commit 663e04c
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/e2e/common/retry_test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def _base_retry_max_redirect_raises(self, max_redirects, expected_call_count):
}
) as conn:
pass

assert "too many redirects" == str(cm.exception.reason)
# Total call count should be 3 (original + 2 retries)
assert mock_obj.return_value.getresponse.call_count == expected_call_count

Expand Down Expand Up @@ -394,3 +394,26 @@ def test_retry_max_redirects_unset_doesnt_redirect_forever(self):

# Total call count should be 6 (original + _retry_stop_after_attempts_count)
assert mock_obj.return_value.getresponse.call_count == 6

def test_retry_max_redirects_is_bounded_by_stop_after_attempts_count(self):
# If I add another 503 or 302 here the test will fail with a MaxRetryError
responses = [
{"status": 302, "headers": {}, "redirect_location": "/foo.bar"},
{"status": 500, "headers": {}, "redirect_location": None},
]

additional_settings = {
"_retry_max_redirects": 1,
"_retry_stop_after_attempts_count": 2,
}

with pytest.raises(RequestError) as cm:
with mock_sequential_server_responses(responses):
with self.connection(
extra_params={**self._retry_policy, **additional_settings}
):
pass

# The error should be the result of the 500, not because of too many requests.
assert "too many redirects" not in str(cm.value.message)
assert "Error during request to server" in str(cm.value.message)

0 comments on commit 663e04c

Please sign in to comment.