Fix flaky tests in advantage_air (#129758)

This commit is contained in:
epenet 2024-11-04 00:25:37 +01:00 committed by GitHub
parent c2ef119e50
commit f11aba9648
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 48 deletions

View File

@ -1,10 +1,8 @@
"""Test the Advantage Air Binary Sensor Platform.""" """Test the Advantage Air Binary Sensor Platform."""
from datetime import timedelta from datetime import timedelta
from unittest.mock import AsyncMock from unittest.mock import AsyncMock, patch
from homeassistant.components.advantage_air import ADVANTAGE_AIR_SYNC_INTERVAL
from homeassistant.config_entries import RELOAD_AFTER_UPDATE_DELAY
from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
@ -70,22 +68,14 @@ async def test_binary_sensor_async_setup_entry(
assert not hass.states.get(entity_id) assert not hass.states.get(entity_id)
mock_get.reset_mock() mock_get.reset_mock()
entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
await hass.async_block_till_done()
async_fire_time_changed( with patch("homeassistant.config_entries.RELOAD_AFTER_UPDATE_DELAY", 1):
hass, entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
dt_util.utcnow() + timedelta(seconds=ADVANTAGE_AIR_SYNC_INTERVAL + 1), await hass.async_block_till_done()
)
await hass.async_block_till_done(wait_background_tasks=True)
assert len(mock_get.mock_calls) == 1
async_fire_time_changed( async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=2))
hass, await hass.async_block_till_done(wait_background_tasks=True)
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1), assert len(mock_get.mock_calls) == 1
)
await hass.async_block_till_done(wait_background_tasks=True)
assert len(mock_get.mock_calls) == 3
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state
@ -101,22 +91,14 @@ async def test_binary_sensor_async_setup_entry(
assert not hass.states.get(entity_id) assert not hass.states.get(entity_id)
mock_get.reset_mock() mock_get.reset_mock()
entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
await hass.async_block_till_done()
async_fire_time_changed( with patch("homeassistant.config_entries.RELOAD_AFTER_UPDATE_DELAY", 1):
hass, entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
dt_util.utcnow() + timedelta(seconds=ADVANTAGE_AIR_SYNC_INTERVAL + 1), await hass.async_block_till_done()
)
await hass.async_block_till_done(wait_background_tasks=True)
assert len(mock_get.mock_calls) == 1
async_fire_time_changed( async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=2))
hass, await hass.async_block_till_done(wait_background_tasks=True)
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1), assert len(mock_get.mock_calls) == 1
)
await hass.async_block_till_done(wait_background_tasks=True)
assert len(mock_get.mock_calls) == 3
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state

View File

@ -1,15 +1,13 @@
"""Test the Advantage Air Sensor Platform.""" """Test the Advantage Air Sensor Platform."""
from datetime import timedelta from datetime import timedelta
from unittest.mock import AsyncMock from unittest.mock import AsyncMock, patch
from homeassistant.components.advantage_air import ADVANTAGE_AIR_SYNC_INTERVAL
from homeassistant.components.advantage_air.const import DOMAIN as ADVANTAGE_AIR_DOMAIN from homeassistant.components.advantage_air.const import DOMAIN as ADVANTAGE_AIR_DOMAIN
from homeassistant.components.advantage_air.sensor import ( from homeassistant.components.advantage_air.sensor import (
ADVANTAGE_AIR_SERVICE_SET_TIME_TO, ADVANTAGE_AIR_SERVICE_SET_TIME_TO,
ADVANTAGE_AIR_SET_COUNTDOWN_VALUE, ADVANTAGE_AIR_SET_COUNTDOWN_VALUE,
) )
from homeassistant.config_entries import RELOAD_AFTER_UPDATE_DELAY
from homeassistant.const import ATTR_ENTITY_ID from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
@ -124,23 +122,15 @@ async def test_sensor_platform_disabled_entity(
assert not hass.states.get(entity_id) assert not hass.states.get(entity_id)
entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
await hass.async_block_till_done(wait_background_tasks=True)
mock_get.reset_mock() mock_get.reset_mock()
async_fire_time_changed( with patch("homeassistant.config_entries.RELOAD_AFTER_UPDATE_DELAY", 1):
hass, entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
dt_util.utcnow() + timedelta(seconds=ADVANTAGE_AIR_SYNC_INTERVAL + 1), await hass.async_block_till_done(wait_background_tasks=True)
)
await hass.async_block_till_done(wait_background_tasks=True)
assert len(mock_get.mock_calls) == 1
async_fire_time_changed( async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=2))
hass, await hass.async_block_till_done(wait_background_tasks=True)
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1), assert len(mock_get.mock_calls) == 1
)
await hass.async_block_till_done(wait_background_tasks=True)
assert len(mock_get.mock_calls) == 3
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state