Don't block startup more than 60 seconds while waiting for components. (#7739)

This commit is contained in:
Anton Sarukhanov 2017-05-23 14:29:27 -07:00 committed by Paulus Schoutsen
parent fce09f624b
commit 7055fddfb4
3 changed files with 40 additions and 6 deletions

View file

@ -13,6 +13,7 @@ from homeassistant.components import group
from homeassistant.helpers.entity import Entity, generate_entity_id
from homeassistant.helpers.entity_component import (
EntityComponent, DEFAULT_SCAN_INTERVAL, SLOW_SETUP_WARNING)
from homeassistant.helpers import entity_component
from homeassistant.helpers import discovery
import homeassistant.util.dt as dt_util
@ -472,7 +473,6 @@ def test_platform_warn_slow_setup(hass):
}
})
assert mock_call.called
assert len(mock_call.mock_calls) == 2
timeout, logger_method = mock_call.mock_calls[0][1][:2]
@ -482,6 +482,30 @@ def test_platform_warn_slow_setup(hass):
assert mock_call().cancel.called
@asyncio.coroutine
def test_platform_error_slow_setup(hass, caplog):
"""Don't block startup more than SLOW_SETUP_MAX_WAIT."""
with patch.object(entity_component, 'SLOW_SETUP_MAX_WAIT', 0):
called = []
@asyncio.coroutine
def setup_platform(*args):
called.append(1)
yield from asyncio.sleep(1, loop=hass.loop)
platform = MockPlatform(async_setup_platform=setup_platform)
component = EntityComponent(_LOGGER, DOMAIN, hass)
loader.set_component('test_domain.test_platform', platform)
yield from component.async_setup({
DOMAIN: {
'platform': 'test_platform',
}
})
assert len(called) == 1
assert 'test_domain.test_platform' not in hass.config.components
assert 'test_platform is taking longer than 0 seconds' in caplog.text
@asyncio.coroutine
def test_extract_from_service_available_device(hass):
"""Test the extraction of entity from service and device is available."""