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
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
skip testing against the recursion limit
  • Loading branch information
Thomas55555 committed Aug 13, 2024
commit 2e878ccfa3d0c006632e1299c36f7e8659c34605
37 changes: 6 additions & 31 deletions tests/components/husqvarna_automower/test_init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Tests for init module."""

import http
import sys
import time
from unittest.mock import AsyncMock, patch

Expand Down Expand Up @@ -139,52 +138,31 @@ async def test_websocket_not_available(
HusqvarnaWSServerHandshakeError("Boom")
)

# Setup integration and verify initial log message
# Setup integration and verify initial log error message
await setup_integration(hass, mock_config_entry)
assert (
"Failed to connect to websocket. Trying to reconnect: Boom" in caplog.text
)

# Initial call count and range for reconnection attempts
mock_automower_client.reset_mock()
default_recursion_limit = sys.getrecursionlimit()
temporary_recursion_limit = 200
sys.setrecursionlimit(temporary_recursion_limit)
assert sys.getrecursionlimit() == temporary_recursion_limit
# Perform reconnection attempts
for count in range(temporary_recursion_limit):
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

# Simulate a successful connection
caplog.clear()
mock_automower_client.auth.websocket_connect.side_effect = None
caplog.clear()
mock_automower_client.reset_mock()
await hass.async_block_till_done()
assert (
mock_automower_client.auth.websocket_connect.call_count
== temporary_recursion_limit + 1
)
assert mock_automower_client.auth.websocket_connect.call_count == 1
assert mock_automower_client.start_listening.call_count == 1
assert "Trying to reconnect: Boom" not in caplog.text

# Simulate a start_listening TimeoutException
mock_automower_client.start_listening.side_effect = TimeoutException("Boom")
await hass.async_block_till_done()
assert (
mock_automower_client.auth.websocket_connect.call_count
== temporary_recursion_limit + 2
)
assert mock_automower_client.auth.websocket_connect.call_count == 2
assert mock_automower_client.start_listening.call_count == 2

# Simulate a successful connection
caplog.clear()
mock_automower_client.start_listening.side_effect = None
await hass.async_block_till_done()
assert (
mock_automower_client.auth.websocket_connect.call_count
== temporary_recursion_limit + 3
)
assert mock_automower_client.auth.websocket_connect.call_count == 3
assert mock_automower_client.start_listening.call_count == 3
assert "Trying to reconnect: Boom" not in caplog.text

Expand All @@ -194,9 +172,6 @@ async def test_websocket_not_available(
assert mock_automower_client.auth.websocket_connect.call_count == 0
assert mock_automower_client.start_listening.call_count == 0

sys.setrecursionlimit(default_recursion_limit)
assert sys.getrecursionlimit() == default_recursion_limit


async def test_device_info(
hass: HomeAssistant,
Expand Down