reach maximum recursion depth exceeded in tests

This commit is contained in:
Thomas Protzner
2024-08-02 19:53:00 +00:00
parent 34b561b211
commit 9645412148
2 changed files with 39 additions and 20 deletions

View File

@@ -69,19 +69,33 @@ class AutomowerDataUpdateCoordinator(DataUpdateCoordinator[dict[str, MowerAttrib
"""Listen with the client."""
try:
await automower_client.auth.websocket_connect()
reconnect_time = 2
await automower_client.start_listening()
except HusqvarnaWSServerHandshakeError as err:
_LOGGER.debug(
"Failed to connect to websocket. Trying to reconnect: %s", err
)
if not hass.is_stopping:
# self.hass.async_create_background_task(
# hass,
# self.client_listen(hass, entry, automower_client),
# "reconnect_task",
# )
reconnect_time = 2
await asyncio.sleep(reconnect_time)
reconnect_time = min(reconnect_time * 2, MAX_WS_RECONNECT_TIME)
await self.client_listen(
hass=hass,
entry=entry,
automower_client=automower_client,
reconnect_time=reconnect_time,
)
else:
await automower_client.start_listening()
if not hass.is_stopping:
await asyncio.sleep(reconnect_time)
reconnect_time = min(reconnect_time * 2, MAX_WS_RECONNECT_TIME)
await self.client_listen(
hass=hass,
entry=entry,
automower_client=automower_client,
reconnect_time=reconnect_time,
)
async def try_reconnect(
self,
hass: HomeAssistant,
entry: ConfigEntry,
automower_client: AutomowerSession,
reconnect_time: int = 2,
) -> None:
"""Listen with the client."""

View File

@@ -15,6 +15,9 @@ import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.husqvarna_automower.const import DOMAIN, OAUTH2_TOKEN
from homeassistant.components.husqvarna_automower.coordinator import (
MAX_WS_RECONNECT_TIME,
)
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
@@ -128,20 +131,22 @@ async def test_websocket_not_available(
freezer: FrozenDateTimeFactory,
) -> None:
"""Test trying reload the websocket."""
mock_automower_client.start_listening.side_effect = HusqvarnaWSServerHandshakeError(
"Boom"
mock_automower_client.auth.websocket_connect.side_effect = (
HusqvarnaWSServerHandshakeError("Boom")
)
await setup_integration(hass, mock_config_entry)
assert "Failed to connect to websocket. Trying to reconnect: Boom" in caplog.text
assert mock_automower_client.auth.websocket_connect.call_count == 1
assert mock_automower_client.start_listening.call_count == 1
assert mock_config_entry.state is ConfigEntryState.LOADED
freezer.tick(timedelta(seconds=2))
async_fire_time_changed(hass)
await hass.async_block_till_done()
assert mock_automower_client.auth.websocket_connect.call_count == 2
assert mock_automower_client.start_listening.call_count == 2
assert mock_config_entry.state is ConfigEntryState.LOADED
reconnect_time = 2
for count in range(1, 945):
reconnect_time = min(reconnect_time * 2, MAX_WS_RECONNECT_TIME)
print("reconnect_t", reconnect_time)
freezer.tick(timedelta(seconds=reconnect_time))
async_fire_time_changed(hass)
await hass.async_block_till_done()
assert mock_automower_client.auth.websocket_connect.call_count == count + 1
assert mock_config_entry.state is ConfigEntryState.LOADED
async def test_device_info(