1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Change core return code processing (#88326)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
modrisb
2023-02-18 03:56:02 +02:00
committed by GitHub
parent 2ea5811e3a
commit 9fd35d53e7
2 changed files with 42 additions and 2 deletions

View File

@@ -181,6 +181,46 @@ async def test_stage_shutdown(hass: HomeAssistant) -> None:
assert len(test_all) == 2
async def test_stage_shutdown_with_exit_code(hass):
"""Simulate a shutdown, test calling stuff with exit code checks."""
test_stop = async_capture_events(hass, EVENT_HOMEASSISTANT_STOP)
test_final_write = async_capture_events(hass, EVENT_HOMEASSISTANT_FINAL_WRITE)
test_close = async_capture_events(hass, EVENT_HOMEASSISTANT_CLOSE)
test_all = async_capture_events(hass, MATCH_ALL)
event_call_counters = [0, 0, 0]
expected_exit_code = 101
async def async_on_stop(event) -> None:
if hass.exit_code == expected_exit_code:
event_call_counters[0] += 1
async def async_on_final_write(event) -> None:
if hass.exit_code == expected_exit_code:
event_call_counters[1] += 1
async def async_on_close(event) -> None:
if hass.exit_code == expected_exit_code:
event_call_counters[2] += 1
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, async_on_stop)
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_FINAL_WRITE, async_on_final_write)
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_CLOSE, async_on_close)
await hass.async_stop(expected_exit_code)
assert len(test_stop) == 1
assert len(test_close) == 1
assert len(test_final_write) == 1
assert len(test_all) == 2
assert (
event_call_counters[0] == 1
and event_call_counters[1] == 1
and event_call_counters[2] == 1
)
async def test_shutdown_calls_block_till_done_after_shutdown_run_callback_threadsafe(
hass,
):