-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added caching to the async session in request.py and AsyncHTTPProvider #2254
Merged
Merged
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
38f7e84
Added caching to the async session in request.py and AsyncHTTPProvider
dbfreem 92ceac1
reverted pytest-mock upgrade
dbfreem ee778ae
Merge branch 'ethereum:master' into feature/async_session_cache
dbfreem 229533f
removed pytest-mock upgrade from news
dbfreem 801638b
Merge branch 'feature/async_session_cache' of https://github.com/dbfr…
dbfreem 3cff06f
made small suggested changes
dbfreem 00f2c67
typo
dbfreem ff12510
added thread lock to the async session cache
dbfreem b9dcffb
Merge branch 'ethereum:master' into feature/async_session_cache
dbfreem e7bbec5
removed lock around close since it was causing deadlocks
dbfreem 097fa1b
accidently commited test that I was working on
dbfreem 3d9e77b
Added SessionCache class
dbfreem eae163d
rearranged the cache code
dbfreem 65b12f2
added one more test on new SessionCache
dbfreem f713776
lint
dbfreem 9656ae8
Had the wrong import not sure how that worked locally
dbfreem 88ee5ac
updated docs
dbfreem 1720df3
fixed updating of existing cache items
dbfreem e307c8b
lint problem again
dbfreem 4289e64
slight changes to docs
dbfreem 8bdcbcd
Moved caching of session in AsynHTTPProvider to a method since it is …
dbfreem 503146d
Merge branch 'ethereum:master' into feature/async_session_cache
dbfreem 92a2b84
Merge branch 'ethereum:master' into feature/async_session_cache
dbfreem e1ff8fe
Merge branch 'ethereum:master' into feature/async_session_cache
dbfreem 40ca5f9
Update docs/providers.rst
dbfreem cf29678
Update web3/_utils/request.py
dbfreem 2d3a275
add _ for confusion reduction
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added session caching to the AsyncHTTPProvider |
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 | ||||
---|---|---|---|---|---|---|
@@ -1,3 +1,8 @@ | ||||||
import pytest | ||||||
|
||||||
from aiohttp import ( | ||||||
ClientSession, | ||||||
) | ||||||
from requests import ( | ||||||
Session, | ||||||
adapters, | ||||||
|
@@ -80,3 +85,19 @@ def test_precached_session(mocker): | |||||
assert isinstance(adapter, HTTPAdapter) | ||||||
assert adapter._pool_connections == 100 | ||||||
assert adapter._pool_maxsize == 100 | ||||||
|
||||||
|
||||||
@pytest.mark.asyncio | ||||||
async def test_async_precached_session(mocker): | ||||||
# Add a session | ||||||
session = ClientSession() | ||||||
request.cache_async_session(URI, session) | ||||||
assert len(request._async_session_cache) == 1 | ||||||
|
||||||
# Make sure the session isn't duplicated | ||||||
request.cache_async_session(URI, session) | ||||||
assert len(request._async_session_cache) == 1 | ||||||
|
||||||
# Make sure a request with a different URI addes another cached session | ||||||
request.cache_async_session("{0}/test".format(URI), session) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick - we tend to prefer using f-strings:
Suggested change
|
||||||
assert len(request._async_session_cache) == 2 |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.