mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Fix flaky recorder test (#80246)
* Fix flaky recorder test * Update tests/components/recorder/test_init.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
parent
d327355afc
commit
2c206ad050
@ -1002,16 +1002,13 @@ def test_statistics_runs_initiated(hass_recorder):
|
|||||||
) - timedelta(minutes=5)
|
) - timedelta(minutes=5)
|
||||||
|
|
||||||
|
|
||||||
def test_compile_missing_statistics(tmpdir):
|
@pytest.mark.freeze_time("2022-09-13 09:00:00+02:00")
|
||||||
|
def test_compile_missing_statistics(tmpdir, freezer):
|
||||||
"""Test missing statistics are compiled on startup."""
|
"""Test missing statistics are compiled on startup."""
|
||||||
now = dt_util.utcnow().replace(minute=0, second=0, microsecond=0)
|
now = dt_util.utcnow().replace(minute=0, second=0, microsecond=0)
|
||||||
test_db_file = tmpdir.mkdir("sqlite").join("test_run_info.db")
|
test_db_file = tmpdir.mkdir("sqlite").join("test_run_info.db")
|
||||||
dburl = f"{SQLITE_URL_PREFIX}//{test_db_file}"
|
dburl = f"{SQLITE_URL_PREFIX}//{test_db_file}"
|
||||||
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.recorder.core.dt_util.utcnow", return_value=now
|
|
||||||
):
|
|
||||||
|
|
||||||
hass = get_test_home_assistant()
|
hass = get_test_home_assistant()
|
||||||
recorder_helper.async_initialize_recorder(hass)
|
recorder_helper.async_initialize_recorder(hass)
|
||||||
setup_component(hass, DOMAIN, {DOMAIN: {CONF_DB_URL: dburl}})
|
setup_component(hass, DOMAIN, {DOMAIN: {CONF_DB_URL: dburl}})
|
||||||
@ -1029,11 +1026,8 @@ def test_compile_missing_statistics(tmpdir):
|
|||||||
wait_recording_done(hass)
|
wait_recording_done(hass)
|
||||||
hass.stop()
|
hass.stop()
|
||||||
|
|
||||||
with patch(
|
# Start Home Assistant one hour later
|
||||||
"homeassistant.components.recorder.core.dt_util.utcnow",
|
freezer.tick(timedelta(hours=1))
|
||||||
return_value=now + timedelta(hours=1),
|
|
||||||
):
|
|
||||||
|
|
||||||
hass = get_test_home_assistant()
|
hass = get_test_home_assistant()
|
||||||
recorder_helper.async_initialize_recorder(hass)
|
recorder_helper.async_initialize_recorder(hass)
|
||||||
setup_component(hass, DOMAIN, {DOMAIN: {CONF_DB_URL: dburl}})
|
setup_component(hass, DOMAIN, {DOMAIN: {CONF_DB_URL: dburl}})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user