Report integrations that block startup wrap up (#56003)

This commit is contained in:
J. Nick Koston 2021-09-10 05:39:22 +02:00 committed by GitHub
parent 2a8121bdcd
commit 5709640453
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 8 deletions

View file

@ -564,6 +564,14 @@ async def _async_set_up_integrations(
except asyncio.TimeoutError: except asyncio.TimeoutError:
_LOGGER.warning("Setup timed out for stage 2 - moving forward") _LOGGER.warning("Setup timed out for stage 2 - moving forward")
# Wrap up startup
_LOGGER.debug("Waiting for startup to wrap up")
try:
async with hass.timeout.async_timeout(WRAP_UP_TIMEOUT, cool_down=COOLDOWN_TIME):
await hass.async_block_till_done()
except asyncio.TimeoutError:
_LOGGER.warning("Setup timed out for bootstrap - moving forward")
watch_task.cancel() watch_task.cancel()
async_dispatcher_send(hass, SIGNAL_BOOTSTRAP_INTEGRATONS, {}) async_dispatcher_send(hass, SIGNAL_BOOTSTRAP_INTEGRATONS, {})
@ -576,11 +584,3 @@ async def _async_set_up_integrations(
) )
}, },
) )
# Wrap up startup
_LOGGER.debug("Waiting for startup to wrap up")
try:
async with hass.timeout.async_timeout(WRAP_UP_TIMEOUT, cool_down=COOLDOWN_TIME):
await hass.async_block_till_done()
except asyncio.TimeoutError:
_LOGGER.warning("Setup timed out for bootstrap - moving forward")

View file

@ -678,6 +678,7 @@ async def test_empty_integrations_list_is_only_sent_at_the_end_of_bootstrap(hass
await bootstrap._async_set_up_integrations( await bootstrap._async_set_up_integrations(
hass, {"normal_integration": {}, "an_after_dep": {}} hass, {"normal_integration": {}, "an_after_dep": {}}
) )
await hass.async_block_till_done()
assert integrations[0] != {} assert integrations[0] != {}
assert "an_after_dep" in integrations[0] assert "an_after_dep" in integrations[0]
@ -686,3 +687,35 @@ async def test_empty_integrations_list_is_only_sent_at_the_end_of_bootstrap(hass
assert "normal_integration" in hass.config.components assert "normal_integration" in hass.config.components
assert order == ["an_after_dep", "normal_integration"] assert order == ["an_after_dep", "normal_integration"]
@pytest.mark.parametrize("load_registries", [False])
async def test_warning_logged_on_wrap_up_timeout(hass, caplog):
"""Test we log a warning on bootstrap timeout."""
def gen_domain_setup(domain):
async def async_setup(hass, config):
await asyncio.sleep(0.1)
async def _background_task():
await asyncio.sleep(0.2)
await hass.async_create_task(_background_task())
return True
return async_setup
mock_integration(
hass,
MockModule(
domain="normal_integration",
async_setup=gen_domain_setup("normal_integration"),
partial_manifest={},
),
)
with patch.object(bootstrap, "WRAP_UP_TIMEOUT", 0):
await bootstrap._async_set_up_integrations(hass, {"normal_integration": {}})
await hass.async_block_till_done()
assert "Setup timed out for bootstrap - moving forward" in caplog.text