Periodically log when integrations are taking a while to setup (#36208)
* Periodicly log when intergrations are taking a while to setup When one or more intergrations are taking a while to setup it is hard to determine which one is the cause. We can help narrow this down for the user with a periodic log message about which domains are still waiting to be setup every 30s. * 30 -> 60 per discussion * only log when the integration is actually doing setup * reduce, fix race in test
This commit is contained in:
parent
e1fd14e00a
commit
5183c40b23
3 changed files with 72 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
|||
"""Test the bootstrapping."""
|
||||
# pylint: disable=protected-access
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
from unittest.mock import Mock
|
||||
|
@ -249,6 +250,7 @@ async def test_setup_hass(
|
|||
mock_mount_local_lib_path,
|
||||
mock_ensure_config_exists,
|
||||
mock_process_ha_config_upgrade,
|
||||
caplog,
|
||||
):
|
||||
"""Test it works."""
|
||||
verbose = Mock()
|
||||
|
@ -259,7 +261,7 @@ async def test_setup_hass(
|
|||
with patch(
|
||||
"homeassistant.config.async_hass_config_yaml",
|
||||
return_value={"browser": {}, "frontend": {}},
|
||||
):
|
||||
), patch.object(bootstrap, "LOG_SLOW_STARTUP_INTERVAL", 5000):
|
||||
hass = await bootstrap.async_setup_hass(
|
||||
config_dir=get_test_config_dir(),
|
||||
verbose=verbose,
|
||||
|
@ -270,6 +272,8 @@ async def test_setup_hass(
|
|||
safe_mode=False,
|
||||
)
|
||||
|
||||
assert "Waiting on integrations to complete setup" not in caplog.text
|
||||
|
||||
assert "browser" in hass.config.components
|
||||
assert "safe_mode" not in hass.config.components
|
||||
|
||||
|
@ -286,6 +290,44 @@ async def test_setup_hass(
|
|||
assert len(mock_process_ha_config_upgrade.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_setup_hass_takes_longer_than_log_slow_startup(
|
||||
mock_enable_logging,
|
||||
mock_is_virtual_env,
|
||||
mock_mount_local_lib_path,
|
||||
mock_ensure_config_exists,
|
||||
mock_process_ha_config_upgrade,
|
||||
caplog,
|
||||
):
|
||||
"""Test it works."""
|
||||
verbose = Mock()
|
||||
log_rotate_days = Mock()
|
||||
log_file = Mock()
|
||||
log_no_color = Mock()
|
||||
|
||||
async def _async_setup_that_blocks_startup(*args, **kwargs):
|
||||
await asyncio.sleep(0.6)
|
||||
return True
|
||||
|
||||
with patch(
|
||||
"homeassistant.config.async_hass_config_yaml",
|
||||
return_value={"browser": {}, "frontend": {}},
|
||||
), patch.object(bootstrap, "LOG_SLOW_STARTUP_INTERVAL", 0.3), patch(
|
||||
"homeassistant.components.frontend.async_setup",
|
||||
side_effect=_async_setup_that_blocks_startup,
|
||||
):
|
||||
await bootstrap.async_setup_hass(
|
||||
config_dir=get_test_config_dir(),
|
||||
verbose=verbose,
|
||||
log_rotate_days=log_rotate_days,
|
||||
log_file=log_file,
|
||||
log_no_color=log_no_color,
|
||||
skip_pip=True,
|
||||
safe_mode=False,
|
||||
)
|
||||
|
||||
assert "Waiting on integrations to complete setup" in caplog.text
|
||||
|
||||
|
||||
async def test_setup_hass_invalid_yaml(
|
||||
mock_enable_logging,
|
||||
mock_is_virtual_env,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue