Avoid lingering timers in update coordinator tests (#89749)

pull/73549/head
epenet 2023-03-15 18:50:32 +01:00 committed by GitHub
parent c416d18506
commit 54ad8b8ee9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -365,7 +365,7 @@ async def test_async_set_updated_data(
def update_callback():
updates.append(crd.data)
crd.async_add_listener(update_callback)
remove_callbacks = crd.async_add_listener(update_callback)
crd.async_set_updated_data(200)
assert updates == [200]
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
assert crd._unsub_refresh is not old_refresh
# Remove callbacks to avoid lingering timers
remove_callbacks()
async def test_stop_refresh_on_ha_stop(
hass: HomeAssistant, crd: update_coordinator.DataUpdateCoordinator[int]
@ -462,7 +465,7 @@ async def test_async_set_update_error(
) -> None:
"""Test manually setting an update failure."""
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"))
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 "Client Failure #2" not in caplog.text
update_callback.assert_called_once()
# Remove callbacks to avoid lingering timers
remove_callbacks()