mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Avoid lingering timers in update coordinator tests (#89749)
This commit is contained in:
parent
c416d18506
commit
54ad8b8ee9
@ -365,7 +365,7 @@ async def test_async_set_updated_data(
|
|||||||
def update_callback():
|
def update_callback():
|
||||||
updates.append(crd.data)
|
updates.append(crd.data)
|
||||||
|
|
||||||
crd.async_add_listener(update_callback)
|
remove_callbacks = crd.async_add_listener(update_callback)
|
||||||
crd.async_set_updated_data(200)
|
crd.async_set_updated_data(200)
|
||||||
assert updates == [200]
|
assert updates == [200]
|
||||||
assert crd._unsub_refresh is not None
|
assert crd._unsub_refresh is not None
|
||||||
@ -376,6 +376,9 @@ async def test_async_set_updated_data(
|
|||||||
# We have created a new refresh listener
|
# We have created a new refresh listener
|
||||||
assert crd._unsub_refresh is not old_refresh
|
assert crd._unsub_refresh is not old_refresh
|
||||||
|
|
||||||
|
# Remove callbacks to avoid lingering timers
|
||||||
|
remove_callbacks()
|
||||||
|
|
||||||
|
|
||||||
async def test_stop_refresh_on_ha_stop(
|
async def test_stop_refresh_on_ha_stop(
|
||||||
hass: HomeAssistant, crd: update_coordinator.DataUpdateCoordinator[int]
|
hass: HomeAssistant, crd: update_coordinator.DataUpdateCoordinator[int]
|
||||||
@ -462,7 +465,7 @@ async def test_async_set_update_error(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test manually setting an update failure."""
|
"""Test manually setting an update failure."""
|
||||||
update_callback = Mock()
|
update_callback = Mock()
|
||||||
crd.async_add_listener(update_callback)
|
remove_callbacks = crd.async_add_listener(update_callback)
|
||||||
|
|
||||||
crd.async_set_update_error(aiohttp.ClientError("Client Failure #1"))
|
crd.async_set_update_error(aiohttp.ClientError("Client Failure #1"))
|
||||||
assert crd.last_update_success is False
|
assert crd.last_update_success is False
|
||||||
@ -486,3 +489,6 @@ async def test_async_set_update_error(
|
|||||||
assert crd.last_update_success is False
|
assert crd.last_update_success is False
|
||||||
assert "Client Failure #2" not in caplog.text
|
assert "Client Failure #2" not in caplog.text
|
||||||
update_callback.assert_called_once()
|
update_callback.assert_called_once()
|
||||||
|
|
||||||
|
# Remove callbacks to avoid lingering timers
|
||||||
|
remove_callbacks()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user