Proceed with startup if an integration setup blocks for more than 30m (#36082)

* Proceed with startup if an integration setup blocks for more than 30m

* Fix test location

* Fix log call

* naming

* revert

* do not shield from cancelation

* Adjust test since we now cancel when we hit the timeout
This commit is contained in:
J. Nick Koston 2020-05-27 13:43:05 -05:00 committed by GitHub
parent 6fbc3b54bd
commit f626129e2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 7 deletions

View file

@ -489,13 +489,16 @@ async def test_component_warn_slow_setup(hass):
result = await setup.async_setup_component(hass, "test_component1", {})
assert result
assert mock_call.called
assert len(mock_call.mock_calls) == 3
assert len(mock_call.mock_calls) == 5
timeout, logger_method = mock_call.mock_calls[0][1][:2]
assert timeout == setup.SLOW_SETUP_WARNING
assert logger_method == setup._LOGGER.warning
timeout, function = mock_call.mock_calls[1][1][:2]
assert timeout == setup.SLOW_SETUP_MAX_WAIT
assert mock_call().cancel.called
@ -507,7 +510,26 @@ async def test_platform_no_warn_slow(hass):
with patch.object(hass.loop, "call_later") as mock_call:
result = await setup.async_setup_component(hass, "test_component1", {})
assert result
assert not mock_call.called
timeout, function = mock_call.mock_calls[0][1][:2]
assert timeout == setup.SLOW_SETUP_MAX_WAIT
async def test_platform_error_slow_setup(hass, caplog):
"""Don't block startup more than SLOW_SETUP_MAX_WAIT."""
with patch.object(setup, "SLOW_SETUP_MAX_WAIT", 1):
called = []
async def async_setup(*args):
"""Tracking Setup."""
called.append(1)
await asyncio.sleep(2)
mock_integration(hass, MockModule("test_component1", async_setup=async_setup))
result = await setup.async_setup_component(hass, "test_component1", {})
assert len(called) == 1
assert not result
assert "test_component1 is taking longer than 1 seconds" in caplog.text
async def test_when_setup_already_loaded(hass):