Make bootstrap cancelation safe (#90420)
This commit is contained in:
parent
e22618a555
commit
f60e9c71a2
2 changed files with 32 additions and 10 deletions
|
@ -515,16 +515,15 @@ async def async_setup_multi_components(
|
||||||
)
|
)
|
||||||
for domain in domains
|
for domain in domains
|
||||||
}
|
}
|
||||||
await asyncio.wait(futures.values())
|
results = await asyncio.gather(*futures.values(), return_exceptions=True)
|
||||||
errors = [domain for domain in domains if futures[domain].exception()]
|
for idx, domain in enumerate(futures):
|
||||||
for domain in errors:
|
result = results[idx]
|
||||||
exception = futures[domain].exception()
|
if isinstance(result, BaseException):
|
||||||
assert exception is not None
|
_LOGGER.error(
|
||||||
_LOGGER.error(
|
"Error setting up integration %s - received exception",
|
||||||
"Error setting up integration %s - received exception",
|
domain,
|
||||||
domain,
|
exc_info=(type(result), result, result.__traceback__),
|
||||||
exc_info=(type(exception), exception, exception.__traceback__),
|
)
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def _async_set_up_integrations(
|
async def _async_set_up_integrations(
|
||||||
|
|
|
@ -806,3 +806,26 @@ async def test_warning_logged_on_wrap_up_timeout(
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert "Setup timed out for bootstrap - moving forward" in caplog.text
|
assert "Setup timed out for bootstrap - moving forward" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("load_registries", [False])
|
||||||
|
async def test_bootstrap_is_cancellation_safe(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
|
"""Test cancellation during async_setup_component does not cancel bootstrap."""
|
||||||
|
with patch.object(
|
||||||
|
bootstrap, "async_setup_component", side_effect=asyncio.CancelledError
|
||||||
|
):
|
||||||
|
await bootstrap._async_set_up_integrations(hass, {"cancel_integration": {}})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert "Error setting up integration cancel_integration" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("load_registries", [False])
|
||||||
|
async def test_bootstrap_empty_integrations(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
|
"""Test setting up an empty integrations does not raise."""
|
||||||
|
await bootstrap.async_setup_multi_components(hass, set(), {})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
Loading…
Add table
Reference in a new issue