mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Cancel discovery flows that are initializing at shutdown (#49241)
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
"""Test the flow classes."""
|
||||
import asyncio
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
@@ -367,3 +370,28 @@ async def test_abort_flow_exception(manager):
|
||||
assert form["type"] == "abort"
|
||||
assert form["reason"] == "mock-reason"
|
||||
assert form["description_placeholders"] == {"placeholder": "yo"}
|
||||
|
||||
|
||||
async def test_initializing_flows_canceled_on_shutdown(hass, manager):
|
||||
"""Test that initializing flows are canceled on shutdown."""
|
||||
|
||||
@manager.mock_reg_handler("test")
|
||||
class TestFlow(data_entry_flow.FlowHandler):
|
||||
async def async_step_init(self, user_input=None):
|
||||
await asyncio.sleep(1)
|
||||
|
||||
task = asyncio.create_task(manager.async_init("test"))
|
||||
await hass.async_block_till_done()
|
||||
await manager.async_shutdown()
|
||||
|
||||
with pytest.raises(asyncio.exceptions.CancelledError):
|
||||
await task
|
||||
|
||||
|
||||
async def test_init_unknown_flow(manager):
|
||||
"""Test that UnknownFlow is raised when async_create_flow returns None."""
|
||||
|
||||
with pytest.raises(data_entry_flow.UnknownFlow), patch.object(
|
||||
manager, "async_create_flow", return_value=None
|
||||
):
|
||||
await manager.async_init("test")
|
||||
|
||||
Reference in New Issue
Block a user