Skip to content
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

Fix RecursionError in Husqvarna Automower coordinator #123085

Merged
merged 28 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9645412
reach maximum recursion depth exceeded in tests
Thomas55555 Aug 2, 2024
95807c6
second background task
Thomas55555 Aug 2, 2024
89d31a5
Update homeassistant/components/husqvarna_automower/coordinator.py
Thomas55555 Aug 2, 2024
dacbc27
Update homeassistant/components/husqvarna_automower/coordinator.py
Thomas55555 Aug 2, 2024
00e21c2
test
Thomas55555 Aug 12, 2024
7b957d1
modify test
Thomas55555 Aug 12, 2024
052aa3e
tests
Thomas55555 Aug 12, 2024
b10ce49
use correct exception
Thomas55555 Aug 12, 2024
dec1b0f
reset mock
Thomas55555 Aug 12, 2024
9e51c57
use recursion_limit
Thomas55555 Aug 12, 2024
99c82f4
remove unneeded ticks
Thomas55555 Aug 12, 2024
3ccdbc3
test TimeoutException
Thomas55555 Aug 12, 2024
b9daf80
set lower recursionlimit
Thomas55555 Aug 12, 2024
40632e3
remove not that important comment and move the other
Thomas55555 Aug 12, 2024
196bbb6
test that we connect and listen successfully
Thomas55555 Aug 12, 2024
8437800
Simulate hass shutting down
Thomas55555 Aug 12, 2024
2e878cc
skip testing against the recursion limit
Thomas55555 Aug 13, 2024
a17e068
Merge branch 'dev' into max-recursion
Thomas55555 Sep 17, 2024
292a201
Update homeassistant/components/husqvarna_automower/coordinator.py
Thomas55555 Sep 17, 2024
f0d6035
Merge branch 'dev' into max-recursion
Thomas55555 Oct 4, 2024
e8ddaea
mock
Thomas55555 Oct 4, 2024
a199c84
Remove comment
Thomas55555 Oct 22, 2024
cb4ebb7
Revert "mock"
emontnemery Nov 11, 2024
142a359
Move patch to decorator
emontnemery Nov 11, 2024
598bc7b
Make execution of patched methods predictable
emontnemery Nov 11, 2024
00f7075
Merge remote-tracking branch 'upstream/dev' into max-recursion
emontnemery Nov 11, 2024
564f4d1
Parametrize test, make mocked start_listening block
emontnemery Nov 11, 2024
e7c256f
Apply suggestions from code review
MartinHjelmare Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
second background task
  • Loading branch information
Thomas55555 committed Aug 2, 2024
commit 95807c66509a00403ec9a0090b0069a62157d51b
23 changes: 4 additions & 19 deletions homeassistant/components/husqvarna_automower/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,13 @@ async def client_listen(
"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,
entry.async_create_background_task(
hass,
self.client_listen(hass, entry, automower_client),
"reconnect_task",
)
else:
await automower_client.start_listening()

async def try_reconnect(
self,
hass: HomeAssistant,
entry: ConfigEntry,
automower_client: AutomowerSession,
reconnect_time: int = 2,
) -> None:
"""Listen with the client."""
9 changes: 8 additions & 1 deletion tests/components/husqvarna_automower/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,19 @@ async def test_websocket_not_available(
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
mock_automower_client.auth.websocket_connect.side_effect = None
freezer.tick(timedelta(seconds=MAX_WS_RECONNECT_TIME))
async_fire_time_changed(hass)
await hass.async_block_till_done()
assert mock_automower_client.start_listening.call_count == 1
mock_automower_client.auth.websocket_connect.side_effect = (
HusqvarnaWSServerHandshakeError("Boom")
)


async def test_device_info(
Expand Down
Loading