Reuse aiohttp sessions per client instance#384
Open
silentgeckoaudit3801 wants to merge 6 commits into
Open
Conversation
|
|
||
|
|
||
| def test_stellar_client_reuses_one_session_and_exposes_close(): | ||
| assert "self._session: aiohttp.ClientSession | None = None" in BLOCKCHAIN_CALL |
|
|
||
| def test_stellar_client_reuses_one_session_and_exposes_close(): | ||
| assert "self._session: aiohttp.ClientSession | None = None" in BLOCKCHAIN_CALL | ||
| assert "async def _get_session(self) -> aiohttp.ClientSession" in BLOCKCHAIN_CALL |
| def test_stellar_client_reuses_one_session_and_exposes_close(): | ||
| assert "self._session: aiohttp.ClientSession | None = None" in BLOCKCHAIN_CALL | ||
| assert "async def _get_session(self) -> aiohttp.ClientSession" in BLOCKCHAIN_CALL | ||
| assert "self._session = aiohttp.ClientSession()" in BLOCKCHAIN_CALL |
| assert "self._session: aiohttp.ClientSession | None = None" in BLOCKCHAIN_CALL | ||
| assert "async def _get_session(self) -> aiohttp.ClientSession" in BLOCKCHAIN_CALL | ||
| assert "self._session = aiohttp.ClientSession()" in BLOCKCHAIN_CALL | ||
| assert "async def close(self) -> None" in BLOCKCHAIN_CALL |
| assert "async def _get_session(self) -> aiohttp.ClientSession" in BLOCKCHAIN_CALL | ||
| assert "self._session = aiohttp.ClientSession()" in BLOCKCHAIN_CALL | ||
| assert "async def close(self) -> None" in BLOCKCHAIN_CALL | ||
| assert "await self._session.close()" in BLOCKCHAIN_CALL |
| assert "async def _get_session(self) -> aiohttp.ClientSession" in API_REQUEST | ||
| assert "self._session = aiohttp.ClientSession(headers=self.DEFAULT_HEADER)" in API_REQUEST | ||
| assert "async def close(self) -> None" in API_REQUEST | ||
| assert API_REQUEST.count("aiohttp.ClientSession(") == 1 |
| assert "self._session = aiohttp.ClientSession(headers=self.DEFAULT_HEADER)" in API_REQUEST | ||
| assert "async def close(self) -> None" in API_REQUEST | ||
| assert API_REQUEST.count("aiohttp.ClientSession(") == 1 | ||
| assert "async with aiohttp.ClientSession" not in API_REQUEST |
|
|
||
|
|
||
| def test_fastapi_dependency_closes_stellar_client_after_request(): | ||
| assert "async def get_stellar_client() -> AsyncIterator[StellarClient]" in DEPENDENCIES |
|
|
||
| def test_fastapi_dependency_closes_stellar_client_after_request(): | ||
| assert "async def get_stellar_client() -> AsyncIterator[StellarClient]" in DEPENDENCIES | ||
| assert "yield client" in DEPENDENCIES |
| def test_fastapi_dependency_closes_stellar_client_after_request(): | ||
| assert "async def get_stellar_client() -> AsyncIterator[StellarClient]" in DEPENDENCIES | ||
| assert "yield client" in DEPENDENCIES | ||
| assert "await client.close()" in DEPENDENCIES No newline at end of file |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
aiohttp.ClientSessionperStellarClientinstance for Horizon/RPC callsAPIRequestinstanceclose()and async context-manager helpers for both clientsget_stellar_clientdependency to yield and close the client after each requestTesting
quantara/web_app/tests/test_aiohttp_session_reuse_static.pyfor CI.Closes #258