Skip to content

Commit

Permalink
Test for aiohttp failure when backoff is used
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Tjarks committed Aug 15, 2018
1 parent c5eb00d commit 51150c4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/python35/test_aiohttp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pytest

import backoff

aiohttp = pytest.importorskip("aiohttp")
aiohttp.web = pytest.importorskip("aiohttp.web")
aiohttp.web_exceptions = pytest.importorskip("aiohttp.web_exceptions")


async def test_backoff_on_all_session_requests(aiohttp_client):
call_count = 0

async def handler(request):
nonlocal call_count
call_count += 1
raise aiohttp.web_exceptions.HTTPUnauthorized

app = aiohttp.web.Application()
app.router.add_get('/', handler)
client = await aiohttp_client(
app,
connector=aiohttp.TCPConnector(limit=1),
raise_for_status=True,
)

# retry every session request
client._session._request = backoff.on_exception(
wait_gen=backoff.expo,
exception=aiohttp.client_exceptions.ClientResponseError,
max_tries=2,
)(client._session._request)

with pytest.raises(aiohttp.client_exceptions.ClientResponseError) as exc:
await client.get('/')

assert exc.value.code == 401
assert call_count == 2

0 comments on commit 51150c4

Please sign in to comment.