Ensure startup can proceed if async_get_integration raises (#50799)

* Ensure startup can proceed if async_get_integration raises

There were cases where the event would never get set and
startup would deadlock because the second attempt to load
the integration would block forever

* pylint

* reorder
This commit is contained in:
J. Nick Koston 2021-05-17 18:32:05 -04:00 committed by GitHub
parent 8129db1cfe
commit a43561e3e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 15 deletions

View file

@ -467,3 +467,32 @@ async def test_get_custom_components_safe_mode(hass):
"""Test that we get empty custom components in safe mode."""
hass.config.safe_mode = True
assert await loader.async_get_custom_components(hass) == {}
async def test_custom_integration_missing_version(hass, caplog):
"""Test trying to load a custom integration without a version twice does not deadlock."""
test_integration_1 = loader.Integration(
hass, "custom_components.test1", None, {"domain": "test1"}
)
with patch("homeassistant.loader.async_get_custom_components") as mock_get:
mock_get.return_value = {
"test1": test_integration_1,
}
with pytest.raises(loader.IntegrationNotFound):
await loader.async_get_integration(hass, "test1")
with pytest.raises(loader.IntegrationNotFound):
await loader.async_get_integration(hass, "test1")
async def test_custom_integration_missing(hass, caplog):
"""Test trying to load a custom integration that is missing twice not deadlock."""
with patch("homeassistant.loader.async_get_custom_components") as mock_get:
mock_get.return_value = {}
with pytest.raises(loader.IntegrationNotFound):
await loader.async_get_integration(hass, "test1")
with pytest.raises(loader.IntegrationNotFound):
await loader.async_get_integration(hass, "test1")