Handle Timeout exceptions in system_health (#50017)

pull/50019/head
Joakim Sørensen 2021-05-03 14:26:25 +02:00 committed by GitHub
parent 378cee01b4
commit 9b89acea97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -216,6 +216,8 @@ async def async_check_can_reach_url(
return "ok"
except aiohttp.ClientError:
data = {"type": "failed", "error": "unreachable"}
if more_info is not None:
data["more_info"] = more_info
return data
except asyncio.TimeoutError:
data = {"type": "failed", "error": "timeout"}
if more_info is not None:
data["more_info"] = more_info
return data

View File

@ -113,6 +113,7 @@ async def test_platform_loading(hass, hass_ws_client, aioclient_mock):
"""Test registering via platform."""
aioclient_mock.get("http://example.com/status", text="")
aioclient_mock.get("http://example.com/status_fail", exc=ClientError)
aioclient_mock.get("http://example.com/timeout", exc=asyncio.TimeoutError)
hass.config.components.add("fake_integration")
mock_platform(
hass,
@ -130,6 +131,11 @@ async def test_platform_loading(hass, hass_ws_client, aioclient_mock):
"http://example.com/status_fail",
more_info="http://more-info-url.com",
),
"server_timeout": system_health.async_check_can_reach_url(
hass,
"http://example.com/timeout",
more_info="http://more-info-url.com",
),
"async_crash": AsyncMock(side_effect=ValueError)(),
}
),
@ -150,6 +156,11 @@ async def test_platform_loading(hass, hass_ws_client, aioclient_mock):
"error": "unreachable",
"more_info": "http://more-info-url.com",
},
"server_timeout": {
"type": "failed",
"error": "timeout",
"more_info": "http://more-info-url.com",
},
"async_crash": {
"type": "failed",
"error": "unknown",