Fix race in starting reauth flows (#103130)

This commit is contained in:
J. Nick Koston
2023-10-31 19:43:05 +01:00
committed by Franck Nijhof
parent 8992d15ffc
commit f0a06efa1f
3 changed files with 40 additions and 6 deletions
+1
View File
@@ -42,6 +42,7 @@ async def test_setup_auth_failed(
config_entry.add_to_hass(hass)
with patch.object(hass.config_entries.flow, "async_init") as mock_flow_init:
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.SETUP_ERROR
mock_flow_init.assert_called_with(
DOMAIN,
+14
View File
@@ -3791,6 +3791,20 @@ async def test_reauth(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
assert len(hass.config_entries.flow.async_progress()) == 2
# Abort all existing flows
for flow in hass.config_entries.flow.async_progress():
hass.config_entries.flow.async_abort(flow["flow_id"])
await hass.async_block_till_done()
# Check that we can't start duplicate reauth flows
# without blocking between flows
entry.async_start_reauth(hass, {"extra_context": "some_extra_context"})
entry.async_start_reauth(hass, {"extra_context": "some_extra_context"})
entry.async_start_reauth(hass, {"extra_context": "some_extra_context"})
entry.async_start_reauth(hass, {"extra_context": "some_extra_context"})
await hass.async_block_till_done()
assert len(hass.config_entries.flow.async_progress()) == 1
async def test_get_active_flows(hass: HomeAssistant) -> None:
"""Test the async_get_active_flows helper."""