Avoid time traveling in recorder tests (#80247)

This commit is contained in:
Erik Montnemery 2022-10-13 11:51:27 +02:00 committed by GitHub
parent 4462f2fc46
commit acb1477673
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,7 @@ from __future__ import annotations
import asyncio import asyncio
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime, timedelta from datetime import datetime
import time import time
from typing import Any, cast from typing import Any, cast
@ -21,8 +21,6 @@ from homeassistant.util import dt as dt_util
from . import db_schema_0 from . import db_schema_0
from tests.common import async_fire_time_changed, fire_time_changed
DEFAULT_PURGE_TASKS = 3 DEFAULT_PURGE_TASKS = 3
@ -69,9 +67,7 @@ def wait_recording_done(hass: HomeAssistant) -> None:
def trigger_db_commit(hass: HomeAssistant) -> None: def trigger_db_commit(hass: HomeAssistant) -> None:
"""Force the recorder to commit.""" """Force the recorder to commit."""
for _ in range(recorder.DEFAULT_COMMIT_INTERVAL): recorder.get_instance(hass)._async_commit(dt_util.utcnow())
# We only commit on time change
fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=1))
async def async_wait_recording_done(hass: HomeAssistant) -> None: async def async_wait_recording_done(hass: HomeAssistant) -> None:
@ -100,8 +96,7 @@ async def async_wait_purge_done(hass: HomeAssistant, max: int = None) -> None:
@ha.callback @ha.callback
def async_trigger_db_commit(hass: HomeAssistant) -> None: def async_trigger_db_commit(hass: HomeAssistant) -> None:
"""Force the recorder to commit. Async friendly.""" """Force the recorder to commit. Async friendly."""
for _ in range(recorder.DEFAULT_COMMIT_INTERVAL): recorder.get_instance(hass)._async_commit(dt_util.utcnow())
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=1))
async def async_recorder_block_till_done(hass: HomeAssistant) -> None: async def async_recorder_block_till_done(hass: HomeAssistant) -> None: