Refactoring test framework from requests to asyncio+aiohttp

32 views
Skip to first unread message

Shreejit Nair

unread,
Dec 3, 2019, 3:47:09 PM12/3/19
to aio-libs
Hi folks,

I am trying to refactor my current api testing framework from requests (synchronous) to asyncio.

I am trying out for a simple get request to an endpoint that responds with data in 2 seconds.

This is how the async version of a test (unit of work) looks like. Just a dummy without assertions.
When I add more tasks similar to the one below, the performance linearly keeps worsening.
I was hoping to get performance closer to "slowest task" but that does not seem to be the case.

asyncio+aiohttp is slightly worse or equal to requests.
Most of the time is spent in getting the response await resp.json() (this typically works within 2 seconds with requests).

But with aiohttp the situation keeps worsening when I add more and more tasks.
I need to run 1000's of http tests and i was hoping this would be the way to make the framework scale.

I am not sure if this is an indication of me doing something wrong or the application being terribly slow.
Running a lot of request based sync versions of the test cases does not show any issues.

async def test_async_order_details11(session):
print("run test order details:{}".format(inspect.stack()[0][3]))
search_index_route = "someroute".format(api_host)
headers = {'Content-type': 'application/json', "Accept": "text/json", "username":"myuser", "apikey":"myauth"}
start = time.time()
async with session.get(search_index_route, headers=headers) as resp:
data = await resp.json()
print("Execution Time to get 1 guy: {}".format(time.time() - start))
print(data)]

Reply all
Reply to author
Forward
0 new messages