mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Improve reliablity of recorder purge test (#92641)
This commit is contained in:
parent
7cb25e9710
commit
ce3cb5864a
@ -38,7 +38,6 @@ from homeassistant.const import EVENT_STATE_CHANGED, EVENT_THEMES_UPDATED, STATE
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
from homeassistant.util.json import json_loads
|
|
||||||
|
|
||||||
from .common import (
|
from .common import (
|
||||||
async_recorder_block_till_done,
|
async_recorder_block_till_done,
|
||||||
@ -1452,6 +1451,11 @@ async def _add_test_events(hass: HomeAssistant, iterations: int = 1):
|
|||||||
five_days_ago = utcnow - timedelta(days=5)
|
five_days_ago = utcnow - timedelta(days=5)
|
||||||
eleven_days_ago = utcnow - timedelta(days=11)
|
eleven_days_ago = utcnow - timedelta(days=11)
|
||||||
event_data = {"test_attr": 5, "test_attr_10": "nice"}
|
event_data = {"test_attr": 5, "test_attr_10": "nice"}
|
||||||
|
# Make sure recording is done before freezing time
|
||||||
|
# because the time freeze can affect the recorder
|
||||||
|
# thread as well can cause the test to fail
|
||||||
|
await async_wait_recording_done(hass)
|
||||||
|
|
||||||
for _ in range(iterations):
|
for _ in range(iterations):
|
||||||
for event_id in range(6):
|
for event_id in range(6):
|
||||||
if event_id < 2:
|
if event_id < 2:
|
||||||
@ -1469,34 +1473,6 @@ async def _add_test_events(hass: HomeAssistant, iterations: int = 1):
|
|||||||
await async_wait_recording_done(hass)
|
await async_wait_recording_done(hass)
|
||||||
|
|
||||||
|
|
||||||
async def _add_events_with_event_data(hass: HomeAssistant, iterations: int = 1):
|
|
||||||
"""Add a few events with linked event_data for testing."""
|
|
||||||
utcnow = dt_util.utcnow()
|
|
||||||
five_days_ago = utcnow - timedelta(days=5)
|
|
||||||
eleven_days_ago = utcnow - timedelta(days=11)
|
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
for _ in range(iterations):
|
|
||||||
for event_id in range(6):
|
|
||||||
if event_id < 2:
|
|
||||||
timestamp = eleven_days_ago
|
|
||||||
event_type = "EVENT_TEST_AUTOPURGE_WITH_EVENT_DATA"
|
|
||||||
shared_data = '{"type":{"EVENT_TEST_AUTOPURGE_WITH_EVENT_DATA"}'
|
|
||||||
elif event_id < 4:
|
|
||||||
timestamp = five_days_ago
|
|
||||||
event_type = "EVENT_TEST_PURGE_WITH_EVENT_DATA"
|
|
||||||
shared_data = '{"type":{"EVENT_TEST_PURGE_WITH_EVENT_DATA"}'
|
|
||||||
else:
|
|
||||||
timestamp = utcnow
|
|
||||||
event_type = "EVENT_TEST_WITH_EVENT_DATA"
|
|
||||||
shared_data = '{"type":{"EVENT_TEST_WITH_EVENT_DATA"}'
|
|
||||||
|
|
||||||
with freeze_time(timestamp):
|
|
||||||
hass.bus.async_fire(event_type, json_loads(shared_data))
|
|
||||||
|
|
||||||
await async_wait_recording_done(hass)
|
|
||||||
|
|
||||||
|
|
||||||
async def _add_test_statistics(hass: HomeAssistant):
|
async def _add_test_statistics(hass: HomeAssistant):
|
||||||
"""Add multiple statistics to the db for testing."""
|
"""Add multiple statistics to the db for testing."""
|
||||||
utcnow = dt_util.utcnow()
|
utcnow = dt_util.utcnow()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user