Fix transport retries after close (#568)

This commit is contained in:
sdb9696 2023-12-05 14:56:29 +00:00 committed by GitHub
parent 4a00199506
commit 01f3827d73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 5 deletions

View File

@ -88,6 +88,8 @@ class AesTransport(BaseTransport):
async def client_post(self, url, params=None, data=None, json=None, headers=None): async def client_post(self, url, params=None, data=None, json=None, headers=None):
"""Send an http post request to the device.""" """Send an http post request to the device."""
if not self._http_client:
self._http_client = httpx.AsyncClient()
response_data = None response_data = None
cookies = None cookies = None
if self._session_cookie: if self._session_cookie:

View File

@ -118,6 +118,8 @@ class KlapTransport(BaseTransport):
async def client_post(self, url, params=None, data=None): async def client_post(self, url, params=None, data=None):
"""Send an http post request to the device.""" """Send an http post request to the device."""
if not self._http_client:
self._http_client = httpx.AsyncClient()
response_data = None response_data = None
cookies = None cookies = None
if self._session_cookie: if self._session_cookie:

View File

@ -32,7 +32,7 @@ class _mock_response:
async def test_protocol_retries(mocker, retry_count, protocol_class, transport_class): async def test_protocol_retries(mocker, retry_count, protocol_class, transport_class):
host = "127.0.0.1" host = "127.0.0.1"
conn = mocker.patch.object( conn = mocker.patch.object(
transport_class, "client_post", side_effect=Exception("dummy exception") httpx.AsyncClient, "post", side_effect=Exception("dummy exception")
) )
with pytest.raises(SmartDeviceException): with pytest.raises(SmartDeviceException):
await protocol_class(host, transport=transport_class(host)).query( await protocol_class(host, transport=transport_class(host)).query(
@ -49,8 +49,8 @@ async def test_protocol_no_retry_on_connection_error(
): ):
host = "127.0.0.1" host = "127.0.0.1"
conn = mocker.patch.object( conn = mocker.patch.object(
transport_class, httpx.AsyncClient,
"client_post", "post",
side_effect=httpx.ConnectError("foo"), side_effect=httpx.ConnectError("foo"),
) )
with pytest.raises(SmartDeviceException): with pytest.raises(SmartDeviceException):
@ -68,8 +68,8 @@ async def test_protocol_retry_recoverable_error(
): ):
host = "127.0.0.1" host = "127.0.0.1"
conn = mocker.patch.object( conn = mocker.patch.object(
transport_class, httpx.AsyncClient,
"client_post", "post",
side_effect=httpx.CloseError("foo"), side_effect=httpx.CloseError("foo"),
) )
with pytest.raises(SmartDeviceException): with pytest.raises(SmartDeviceException):