mirror of
https://github.com/home-assistant/core.git
synced 2026-09-27 18:08:37 -04:00
Shutdown coordinator on entry unload (#91748)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
@@ -182,7 +182,7 @@ async def test_immediate_works_with_function_swapped(hass: HomeAssistant) -> Non
|
||||
assert debouncer._job.target == debouncer.function
|
||||
|
||||
|
||||
async def test_shutdown(hass: HomeAssistant) -> None:
|
||||
async def test_shutdown(hass: HomeAssistant, caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""Test shutdown."""
|
||||
calls = []
|
||||
future = asyncio.Future()
|
||||
@@ -208,5 +208,9 @@ async def test_shutdown(hass: HomeAssistant) -> None:
|
||||
assert len(calls) == 1
|
||||
assert debouncer._timer_task is None
|
||||
|
||||
with pytest.raises(RuntimeError, match="Debouncer has been shutdown"):
|
||||
await debouncer.async_call()
|
||||
assert "Debouncer call ignored as shutdown has been requested." not in caplog.text
|
||||
await debouncer.async_call()
|
||||
assert "Debouncer call ignored as shutdown has been requested." in caplog.text
|
||||
|
||||
assert len(calls) == 1
|
||||
assert debouncer._timer_task is None
|
||||
|
||||
@@ -153,6 +153,39 @@ async def test_shutdown(
|
||||
assert updates == [2]
|
||||
|
||||
|
||||
async def test_shutdown_on_entry_unload(
|
||||
hass: HomeAssistant,
|
||||
crd: update_coordinator.DataUpdateCoordinator[int],
|
||||
) -> None:
|
||||
"""Test shutdown is requested on entry unload."""
|
||||
entry = MockConfigEntry()
|
||||
config_entries.current_entry.set(entry)
|
||||
|
||||
calls = 0
|
||||
|
||||
async def _refresh() -> int:
|
||||
nonlocal calls
|
||||
calls += 1
|
||||
return calls
|
||||
|
||||
crd = update_coordinator.DataUpdateCoordinator[int](
|
||||
hass,
|
||||
_LOGGER,
|
||||
name="test",
|
||||
update_method=_refresh,
|
||||
update_interval=DEFAULT_UPDATE_INTERVAL,
|
||||
)
|
||||
|
||||
crd.async_add_listener(lambda: None)
|
||||
assert crd._unsub_refresh is not None
|
||||
assert not crd._shutdown_requested
|
||||
|
||||
await entry._async_process_on_unload(hass)
|
||||
|
||||
assert crd._shutdown_requested
|
||||
assert crd._unsub_refresh is None
|
||||
|
||||
|
||||
async def test_update_context(
|
||||
crd: update_coordinator.DataUpdateCoordinator[int],
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user