Prevent spawning script runs when shutting down (#68170)

This commit is contained in:
Erik Montnemery 2022-03-15 12:46:58 +01:00 committed by GitHub
parent f7cb10e2f5
commit 1a27025793
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View file

@ -3276,6 +3276,26 @@ async def test_shutdown_after(hass, caplog):
assert_action_trace(expected_trace)
async def test_start_script_after_shutdown(hass, caplog):
"""Test starting scripts after shutdown is blocked."""
delay_alias = "delay step"
sequence = cv.SCRIPT_SCHEMA({"delay": {"seconds": 120}, "alias": delay_alias})
script_obj = script.Script(hass, sequence, "test script", "test_domain")
# Trigger 1st stage script shutdown
hass.state = CoreState.stopping
hass.bus.async_fire("homeassistant_stop")
await hass.async_block_till_done()
# Trigger 2nd stage script shutdown
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=60))
await hass.async_block_till_done()
# Attempt to spawn additional script run
await script_obj.async_run(context=Context())
assert not script_obj.is_running
assert "Home Assistant is shutting down, starting script blocked" in caplog.text
async def test_update_logger(hass, caplog):
"""Test updating logger."""
sequence = cv.SCRIPT_SCHEMA({"event": "test_event"})