Avoid sending empty integration list multiple times during subscribe_bootstrap_integrations (#49181)
This commit is contained in:
@@ -7,8 +7,10 @@ from unittest.mock import Mock, patch
|
||||
import pytest
|
||||
|
||||
from homeassistant import bootstrap, core, runner
|
||||
from homeassistant.bootstrap import SIGNAL_BOOTSTRAP_INTEGRATONS
|
||||
import homeassistant.config as config_util
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.common import (
|
||||
@@ -610,3 +612,60 @@ async def test_setup_safe_mode_if_no_frontend(
|
||||
assert hass.config.skip_pip
|
||||
assert hass.config.internal_url == "http://192.168.1.100:8123"
|
||||
assert hass.config.external_url == "https://abcdef.ui.nabu.casa"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("load_registries", [False])
|
||||
async def test_empty_integrations_list_is_only_sent_at_the_end_of_bootstrap(hass):
|
||||
"""Test empty integrations list is only sent at the end of bootstrap."""
|
||||
order = []
|
||||
|
||||
def gen_domain_setup(domain):
|
||||
async def async_setup(hass, config):
|
||||
order.append(domain)
|
||||
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={"after_dependencies": ["an_after_dep"]},
|
||||
),
|
||||
)
|
||||
mock_integration(
|
||||
hass,
|
||||
MockModule(
|
||||
domain="an_after_dep",
|
||||
async_setup=gen_domain_setup("an_after_dep"),
|
||||
),
|
||||
)
|
||||
|
||||
integrations = []
|
||||
|
||||
@core.callback
|
||||
def _bootstrap_integrations(data):
|
||||
integrations.append(data)
|
||||
|
||||
async_dispatcher_connect(
|
||||
hass, SIGNAL_BOOTSTRAP_INTEGRATONS, _bootstrap_integrations
|
||||
)
|
||||
with patch.object(bootstrap, "SLOW_STARTUP_CHECK_INTERVAL", 0.05):
|
||||
await bootstrap._async_set_up_integrations(
|
||||
hass, {"normal_integration": {}, "an_after_dep": {}}
|
||||
)
|
||||
|
||||
assert integrations[0] != {}
|
||||
assert "an_after_dep" in integrations[0]
|
||||
assert integrations[-3] != {}
|
||||
assert integrations[-1] == {}
|
||||
|
||||
assert "normal_integration" in hass.config.components
|
||||
assert order == ["an_after_dep", "normal_integration"]
|
||||
|
||||
Reference in New Issue
Block a user