Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 9 additions & 6 deletions tests/components/rflink/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,26 @@ async def test_default_setup(
assert hass.states.get("binary_sensor.test").state == STATE_OFF


@pytest.mark.xfail(
reason="Flaky due to Python 3.14.3 asyncio changes - see home-assistant/core#162263"
)
async def test_entity_availability(
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
) -> None:
"""If Rflink device is disconnected, entities should become unavailable."""
# Make sure Rflink mock does not 'recover' to quickly from the
# disconnect or else the unavailability cannot be measured
config = CONFIG
failures = [True, True]
config[CONF_RECONNECT_INTERVAL] = 60
config = {
**CONFIG,
"rflink": {
**CONFIG["rflink"],
CONF_RECONNECT_INTERVAL: 60,
},
}
failures = [False, True]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it now False True?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The short answer is because is how tests must work.
failures is to mock the create_rflink_connection method called during initialization and reconnections:
https://github.com/javicalle/home-assistant/blob/60cd4a999116b3967215481eab5fb1f1fa40d037/tests/components/rflink/test_init.py#L65-L66
In that tests, during the RFLink initialization the connection must be fine (failure=False) and must create the configured entities but state would be unknown.
After the disconnect_callback call, RFLink will try to reconnect but will fail (failure=True) and should make entities unavailable

Not sure how has been working until now this way. That part of tests has been this way for years. It's possible that the accumulation of errors caused the test to work, because after adding the await hass.async_block_till_done() sentence, 3 bugs has been detected:

  • the fail = failures.pop(0) # removes from left to right (maybe not a bug but very confuse at least)
  • the failures = [False, True] to manage failures (probably failures = [False, True, False] would be better to make explicit the second await hass.async_block_till_done() in tests)
  • the config[CONF_RECONNECT_INTERVAL] = 60 was wrong and must be config['rflink'][CONF_RECONNECT_INTERVAL] = 60 (fixed in new code)

I hope this answers your questions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks


# Create platform and entities
event_callback, _, _, disconnect_callback = await mock_rflink(
hass, config, DOMAIN, monkeypatch, failures=failures
)
await hass.async_block_till_done()

# Entities are unknown by default
assert hass.states.get("binary_sensor.test").state == STATE_UNKNOWN
Expand Down
2 changes: 1 addition & 1 deletion tests/components/rflink/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async def create_rflink_connection(*args, **kwargs):
# failures can be a list of booleans indicating in which sequence
# creating a connection should success or fail
if failures:
fail = failures.pop()
fail = failures.pop(0) # removes from left to right
else:
fail = False

Expand Down
15 changes: 9 additions & 6 deletions tests/components/rflink/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,26 @@ async def test_disable_automatic_add(
assert not hass.states.get("sensor.test2")


@pytest.mark.xfail(
reason="Flaky due to Python 3.14.3 asyncio changes - see home-assistant/core#162263"
)
async def test_entity_availability(
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
) -> None:
"""If Rflink device is disconnected, entities should become unavailable."""
# Make sure Rflink mock does not 'recover' to quickly from the
# disconnect or else the unavailability cannot be measured
config = CONFIG
failures = [True, True]
config[CONF_RECONNECT_INTERVAL] = 60
config = {
**CONFIG,
"rflink": {
**CONFIG["rflink"],
CONF_RECONNECT_INTERVAL: 60,
},
}
failures = [False, True]

Comment thread
javicalle marked this conversation as resolved.
# Create platform and entities
_, _, _, disconnect_callback = await mock_rflink(
hass, config, DOMAIN, monkeypatch, failures=failures
)
await hass.async_block_till_done()

# Entities are available by default
assert hass.states.get("sensor.test").state == STATE_UNKNOWN
Expand Down
Loading