Remove extra timeouts (#610)

This commit is contained in:
J. Nick Koston 2023-10-31 23:20:22 -05:00 committed by GitHub
parent 1d2682a76e
commit 8357a3a0c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 24 deletions

View File

@ -87,9 +87,6 @@ CONNECT_REQUEST_TIMEOUT = 30.0
# to reboot and connect to the network/WiFi.
TCP_CONNECT_TIMEOUT = 60.0
# The maximum time for the whole connect process to complete
CONNECT_AND_SETUP_TIMEOUT = 120.0
# How long to wait for an existing connection to finish being
# setup when requesting a disconnect so we can try to disconnect
# gracefully without closing the socket out from under the
@ -500,11 +497,7 @@ class APIConnection:
)
self._start_connect_task = start_connect_task
try:
# Allow 2 minutes for connect and setup; this is only as a last measure
# to protect from issues if some part of the connect process mistakenly
# does not have a timeout
async with asyncio_timeout(CONNECT_AND_SETUP_TIMEOUT):
await start_connect_task
await start_connect_task
except (Exception, CancelledError) as ex:
# If the task was cancelled, we need to clean up the connection
# and raise the CancelledError as APIConnectionError
@ -554,11 +547,7 @@ class APIConnection:
)
self._finish_connect_task = finish_connect_task
try:
# Allow 2 minutes for connect and setup; this is only as a last measure
# to protect from issues if some part of the connect process mistakenly
# does not have a timeout
async with asyncio_timeout(CONNECT_AND_SETUP_TIMEOUT):
await self._finish_connect_task
await self._finish_connect_task
except (Exception, CancelledError) as ex:
# If the task was cancelled, we need to clean up the connection
# and raise the CancelledError as APIConnectionError

View File

@ -333,21 +333,19 @@ async def test_start_connection_times_out(
"""Test handling of start connection timing out."""
loop = asyncio.get_event_loop()
async def _create_mock_transport_protocol(create_func, **kwargs):
async def _mock_socket_connect(*args, **kwargs):
await asyncio.sleep(500)
with patch.object(
loop, "create_connection", side_effect=_create_mock_transport_protocol
with patch.object(loop, "sock_connect", side_effect=_mock_socket_connect), patch(
"aioesphomeapi.connection.TCP_CONNECT_TIMEOUT", 0.0
):
connect_task = asyncio.create_task(connect(conn, login=False))
await asyncio.sleep(0)
async_fire_time_changed(utcnow() + timedelta(seconds=200))
await asyncio.sleep(0)
async_fire_time_changed(utcnow() + timedelta(seconds=200))
await asyncio.sleep(0)
with pytest.raises(
APIConnectionError, match="Error while starting connection: TimeoutError"
):
with pytest.raises(APIConnectionError, match="Timeout while connecting"):
await connect_task
async_fire_time_changed(utcnow() + timedelta(seconds=600))
@ -444,9 +442,7 @@ async def test_finish_connection_times_out(
async_fire_time_changed(utcnow() + timedelta(seconds=200))
await asyncio.sleep(0)
with pytest.raises(
APIConnectionError, match="Error while finishing connection: TimeoutError"
):
with pytest.raises(APIConnectionError, match="Hello timed out"):
await connect_task
async_fire_time_changed(utcnow() + timedelta(seconds=600))