8000 Fix flaky vizio test and add comments to explain logic by raman325 · Pull Request #50948 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix flaky vizio test and add comments to explain logic #50948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions homeassistant/components/vizio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ async def _async_update_data(self) -> list[dict[str, Any]]:
"""Update data via library."""
data = await gen_apps_list_from_url(session=async_get_clientsession(self.hass))
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:
_LOGGER.warning(
(
Expand All @@ -126,6 +129,7 @@ async def _async_update_data(self) -> list[dict[str, Any]]:
else:
self.fail_count += 1
return self.data
# Reset the fail count and threshold when the data is successfully retrieved
self.fail_count = 0
self.fail_threshold = 10
return sorted(data, key=lambda app: app["name"])
13 changes: 5 additions & 8 deletions tests/components/vizio/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,11 @@ async def test_coordinator_update_failure(
assert len(hass.states.async_entity_ids(MP_DOMAIN)) == 1
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))
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))
await hass.async_block_till_done()
assert "Unable to retrieve the apps list from the external server" in caplog.text
err_msg = "Unable to retrieve the apps list from the external server"
assert len([record for record in caplog.records if err_msg in record.msg]) == 1
0