Skip to content

Commit b7ffd70

Browse files
committed
More specific naming for session manager:
- ``RequestSessionManager`` -> ``HTTPSessionManager`` - Move default timeout for http from ``_utils/request.py`` -> ``_utils/http.py``. This eliminates the need for a ``request.py`` utils since ``HTTPSessionManager`` lives in its own file at ``_utils/http_session_manager.py```. - Pass the configured timeout to sync and async ``cache_and_return_session`` methods. Previously, we were using the hard-coded default value and if the call is coming from a provider (99% of the time), rather than the request method being invoked directly, we would be using the wrong value when spinning off any session closing tasks.
1 parent e6b6096 commit b7ffd70

File tree

10 files changed

+138
-129
lines changed

10 files changed

+138
-129
lines changed

newsfragments/3412.internal.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Use a ``RequestSessionManager`` to manage sessions for http providers, rather than have them share a single session manager / cache.
1+
Use a ``HTTPSessionManager`` to manage sessions for http providers, rather than have them share a single session manager / cache.

tests/core/providers/test_http_request_retry.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_check_without_retry_config():
5353
w3 = Web3(HTTPProvider(exception_retry_configuration=None))
5454

5555
with patch(
56-
"web3.providers.rpc.rpc.RequestSessionManager.make_post_request"
56+
"web3.providers.rpc.rpc.HTTPSessionManager.make_post_request"
5757
) as make_post_request_mock:
5858
make_post_request_mock.side_effect = Timeout
5959

@@ -72,7 +72,7 @@ def test_check_if_retry_on_failure_true():
7272

7373

7474
@patch(
75-
"web3.providers.rpc.rpc.RequestSessionManager.make_post_request",
75+
"web3.providers.rpc.rpc.HTTPSessionManager.make_post_request",
7676
side_effect=ConnectionError,
7777
)
7878
def test_check_send_transaction_called_once(make_post_request_mock, w3):
@@ -84,7 +84,7 @@ def test_check_send_transaction_called_once(make_post_request_mock, w3):
8484

8585

8686
@patch(
87-
"web3.providers.rpc.rpc.RequestSessionManager.make_post_request",
87+
"web3.providers.rpc.rpc.HTTPSessionManager.make_post_request",
8888
side_effect=ConnectionError,
8989
)
9090
def test_valid_method_retried(make_post_request_mock, w3):
@@ -105,7 +105,7 @@ def test_exception_retry_config_is_strictly_on_http_provider():
105105

106106

107107
@patch(
108-
"web3.providers.rpc.rpc.RequestSessionManager.make_post_request",
108+
"web3.providers.rpc.rpc.HTTPSessionManager.make_post_request",
109109
side_effect=ConnectionError,
110110
)
111111
def test_exception_retry_middleware_with_allow_list_kwarg(make_post_request_mock):
@@ -159,7 +159,7 @@ async def test_async_default_request_retry_configuration_for_http_provider():
159159
)
160160
async def test_async_check_retry_middleware(async_w3, error):
161161
with patch(
162-
"web3.providers.rpc.async_rpc.RequestSessionManager.async_make_post_request"
162+
"web3.providers.rpc.async_rpc.HTTPSessionManager.async_make_post_request"
163163
) as async_make_post_request_mock:
164164
async_make_post_request_mock.side_effect = error
165165

@@ -173,7 +173,7 @@ async def test_async_check_without_retry_config():
173173
w3 = AsyncWeb3(AsyncHTTPProvider(exception_retry_configuration=None))
174174

175175
with patch(
176-
"web3.providers.rpc.async_rpc.RequestSessionManager.async_make_post_request"
176+
"web3.providers.rpc.async_rpc.HTTPSessionManager.async_make_post_request"
177177
) as async_make_post_request_mock:
178178
async_make_post_request_mock.side_effect = TimeoutError
179179

@@ -192,7 +192,7 @@ async def test_async_exception_retry_middleware_with_allow_list_kwarg():
192192
async_w3 = AsyncWeb3(AsyncHTTPProvider(exception_retry_configuration=config))
193193

194194
with patch(
195-
"web3.providers.rpc.async_rpc.RequestSessionManager.async_make_post_request"
195+
"web3.providers.rpc.async_rpc.HTTPSessionManager.async_make_post_request"
196196
) as async_make_post_request_mock:
197197
async_make_post_request_mock.side_effect = TimeoutError
198198

0 commit comments

Comments
 (0)