-
-
Notifications
You must be signed in to change notification settings - Fork 35.7k
Add a regression test for airq integration stalling #155511
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
Draft
Sibgatulin
wants to merge
1
commit into
home-assistant:dev
Choose a base branch
from
CorantGmbH:airq_stalling_regression_test
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
tests/components/airq/test_integration_stalling_regression.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| """Test that the coordinator does not hang with unresponding server. | ||
|
|
||
| Users reported that the integration was stalling silently at random intervals. | ||
| This was identified to be due to an incorrect timeout in aioairq and was fixed | ||
| in aioairq==0.4.7 and homeassistant==2025.10.3. | ||
| This is the regression test. | ||
| """ | ||
|
|
||
| import asyncio | ||
| import time | ||
|
|
||
| import pytest | ||
| import pytest_asyncio | ||
|
|
||
| from homeassistant.components.airq import AirQCoordinator | ||
| from homeassistant.components.airq.const import DOMAIN | ||
| from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD | ||
| from homeassistant.core import HomeAssistant | ||
|
|
||
| from tests.common import MockConfigEntry | ||
|
|
||
| TIMEOUT_DEFAULT = 15 | ||
| TIMEOUT_HANGING = TIMEOUT_DEFAULT * 3 | ||
| TIMEOUT_SAFETY = TIMEOUT_DEFAULT * 2 | ||
| IP = "127.0.0.1" | ||
|
|
||
|
|
||
| @pytest_asyncio.fixture | ||
| async def hanging_server(): | ||
| """TCP server that accepts connections but never sends data. | ||
|
|
||
| This makes HTTP clients wait forever for the status line / headers. | ||
| """ | ||
|
|
||
| async def handler(reader: asyncio.StreamReader, writer: asyncio.StreamWriter): | ||
| try: | ||
| # Keep the connection open; don't read or write HTTP data. | ||
| await asyncio.sleep(TIMEOUT_HANGING) | ||
| finally: | ||
| writer.close() | ||
|
|
||
| # pick any free ephemeral port on localhost and bind the server to it | ||
| server = await asyncio.start_server(handler, host=IP, port=0) | ||
| # get the actual selected port | ||
| port = server.sockets[0].getsockname()[1] | ||
| try: | ||
| yield (IP, port) | ||
| finally: | ||
| server.close() | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("socket_enabled") | ||
| async def test_coordinator_timeout_with_hanging_device( | ||
| hass: HomeAssistant, | ||
| hanging_server, | ||
| ) -> None: | ||
| """Test that AirQCoordinator times out by itself instead of getting stuck.""" | ||
| host, port = hanging_server | ||
|
|
||
| # Create config entry with the actual hanging server address | ||
| config_entry = MockConfigEntry( | ||
| domain=DOMAIN, | ||
| data={ | ||
| CONF_IP_ADDRESS: f"{host}:{port}", # Use actual port! | ||
| CONF_PASSWORD: "test_password", | ||
| }, | ||
| unique_id="test_hanging_device", | ||
| ) | ||
|
|
||
| # Create coordinator | ||
| coordinator = AirQCoordinator(hass, config_entry) | ||
|
|
||
| started = time.perf_counter() | ||
|
|
||
| with pytest.raises(asyncio.TimeoutError): | ||
| async with asyncio.timeout(TIMEOUT_SAFETY): | ||
| await coordinator._async_update_data() | ||
|
|
||
| elapsed = time.perf_counter() - started | ||
|
|
||
| assert elapsed < TIMEOUT_DEFAULT + 1, ( | ||
| f"Expected ~{TIMEOUT_DEFAULT}s, got {elapsed:.1f}s (aioairq==0.4.6 behavior)" | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be in test_init.py, to be consistent with most of the codebase.
Also, we should not interact directly with the coordinator or other integration internals: https://developers.home-assistant.io/docs/development_testing/#writing-tests-for-integrations
Can we refactor this to avoid interacting with the internals?