-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6509809
commit ea04add
Showing
5 changed files
with
450 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -195,4 +195,3 @@ async def retry_async_gen_func(*args, **kwargs): | |
if func: | ||
return decorator(func) | ||
return decorator | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from reattempt import reattempt | ||
from test.conftest import MAX_ATTEMPTS, MIN_TIME, MAX_TIME | ||
import pytest | ||
import aiohttp | ||
|
||
|
||
@reattempt(max_retries=MAX_ATTEMPTS, min_time=MIN_TIME, max_time=MAX_TIME) | ||
async def async_aiohttp_call(status: int): | ||
async_aiohttp_call.counter += 1 | ||
|
||
async with aiohttp.ClientSession() as session: | ||
async with session.get( | ||
f"https://httpbin.org/status/{status}", ssl=False | ||
) as response: | ||
response.raise_for_status() | ||
return "OK" | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_retry_http_200(): | ||
async_aiohttp_call.counter = 0 # type: ignore | ||
|
||
await async_aiohttp_call(200) | ||
assert async_aiohttp_call.counter == 1 # type: ignore | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_retry_http_500(): | ||
async_aiohttp_call.counter = 0 # type: ignore | ||
|
||
try: | ||
await async_aiohttp_call(500) | ||
pytest.fail("Must not come here") | ||
except Exception: | ||
print("Success") | ||
assert async_aiohttp_call.counter == MAX_ATTEMPTS # type: ignore |
Oops, something went wrong.