mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Fix flaky vizio test and add comments to explain logic (#50948)
This commit is contained in:
parent
78be237447
commit
92d1871de5
@ -113,6 +113,9 @@ class VizioAppsDataUpdateCoordinator(DataUpdateCoordinator):
|
|||||||
"""Update data via library."""
|
"""Update data via library."""
|
||||||
data = await gen_apps_list_from_url(session=async_get_clientsession(self.hass))
|
data = await gen_apps_list_from_url(session=async_get_clientsession(self.hass))
|
||||||
if not data:
|
if not data:
|
||||||
|
# For every failure, increase the fail count until we reach the threshold.
|
||||||
|
# We then log a warning, increase the threshold, and reset the fail count.
|
||||||
|
# This is here to prevent silent failures but to reduce repeat logs.
|
||||||
if self.fail_count == self.fail_threshold:
|
if self.fail_count == self.fail_threshold:
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
(
|
(
|
||||||
@ -126,6 +129,7 @@ class VizioAppsDataUpdateCoordinator(DataUpdateCoordinator):
|
|||||||
else:
|
else:
|
||||||
self.fail_count += 1
|
self.fail_count += 1
|
||||||
return self.data
|
return self.data
|
||||||
|
# Reset the fail count and threshold when the data is successfully retrieved
|
||||||
self.fail_count = 0
|
self.fail_count = 0
|
||||||
self.fail_threshold = 10
|
self.fail_threshold = 10
|
||||||
return sorted(data, key=lambda app: app["name"])
|
return sorted(data, key=lambda app: app["name"])
|
||||||
|
@ -94,14 +94,11 @@ async def test_coordinator_update_failure(
|
|||||||
assert len(hass.states.async_entity_ids(MP_DOMAIN)) == 1
|
assert len(hass.states.async_entity_ids(MP_DOMAIN)) == 1
|
||||||
assert DOMAIN in hass.data
|
assert DOMAIN in hass.data
|
||||||
|
|
||||||
for days in range(1, 10):
|
# Failing 25 days in a row should result in a single log message
|
||||||
|
# (first one after 10 days, next one would be at 30 days)
|
||||||
|
for days in range(1, 25):
|
||||||
async_fire_time_changed(hass, now + timedelta(days=days))
|
async_fire_time_changed(hass, now + timedelta(days=days))
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert (
|
|
||||||
"Unable to retrieve the apps list from the external server"
|
|
||||||
not in caplog.text
|
|
||||||
)
|
|
||||||
|
|
||||||
async_fire_time_changed(hass, now + timedelta(days=10))
|
err_msg = "Unable to retrieve the apps list from the external server"
|
||||||
await hass.async_block_till_done()
|
assert len([record for record in caplog.records if err_msg in record.msg]) == 1
|
||||||
assert "Unable to retrieve the apps list from the external server" in caplog.text
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user