Skip to content

Conversation

@jgr-ableton
Copy link

This branch adds asyncio support to all API endpoints to make them non-blocking, using asyncio and aiohttp.

  • Used aiohttp to make the two requests for data sources instead of requests, as requests is not compatible with asyncio. A key piece of this is the addition of a global aiohttp.ClientSession instance, which exists for the entire application run.
  • Updated methods up the call chain with async/await as necessary.
  • Updated the endpoint methods to be async as per https://fastapi.tiangolo.com/async/.
  • Updated the tests to handle asynchronous calls.
  • Added tests for the setup and teardown of the global ClientSession.

Added dependencies:

  • aiohttp
  • asyncache
  • async-asgi-testclient
  • pytest-asyncio

#232

These are required to be able to test asyncio functionality, as well as making ASGI test clients play nice asynchronously.
- Move test fixtures into tests/fixtures.py
- Update test fixtures to mock aiohttp.ClientSession.get, instead of requests.get
- Add a context manager to replace the global httputils.client_session with an AsyncMock
- Misc. cleanup
I didn't see this file when I first added the new fixtures.
One can still define a separate responder function here, but since this is the
only response defined for the tests thus far, this seems like a reasonable default.
@jgr-ableton jgr-ableton closed this Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants