Skip to content

Commit

Permalink
Fix retry behaviour when responses are successful (fixes #129)
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed May 10, 2017
1 parent 1a6ea96 commit 4e011c8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ This document describes changes between each past release.
- Keep tracks of Backoff headers and raise an ``BackoffException`` if
we are not waiting enough between two calls. (#53)

**Bug fixes**

- Fix retry behaviour when responses are successful (fixes #129)


7.2.0 (2017-03-17)
==================
Expand Down
5 changes: 4 additions & 1 deletion kinto_http/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ def request(self, method, endpoint, data=None, permissions=None,
self.backoff = None

retry = retry - 1
if not (200 <= resp.status_code < 400):
if 200 <= resp.status_code < 400:
# Success
break
else:
if resp.status_code >= 500 and retry >= 0:
# Wait and try again.
# If not forced, use retry-after header and wait.
Expand Down
6 changes: 6 additions & 0 deletions kinto_http/tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ def test_does_not_retry_by_default(self):
with self.assertRaises(KintoException):
session.request('GET', '/v1/foobar')

def test_does_not_retry_if_successful(self):
self.requests_mock.request.side_effect = [self.response_200,
self.response_403] # retry 1
session = Session('https://example.org', retry=1)
session.request('GET', '/v1/foobar') # Not raising.

def test_succeeds_on_retry(self):
self.requests_mock.request.side_effect = [self.response_503,
self.response_200] # retry 1
Expand Down

0 comments on commit 4e011c8

Please sign in to comment.