Auto repack the database on the second sunday of the month (#69314)

This commit is contained in:
J. Nick Koston 2022-04-04 21:39:12 -10:00 committed by GitHub
parent 0ab866cd23
commit ec131d685e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 164 additions and 4 deletions

View file

@ -1,5 +1,5 @@
"""Test util methods."""
from datetime import timedelta
from datetime import datetime, timedelta
import os
import sqlite3
from unittest.mock import MagicMock, patch
@ -12,7 +12,11 @@ from homeassistant.components import recorder
from homeassistant.components.recorder import run_information_with_session, util
from homeassistant.components.recorder.const import DATA_INSTANCE, SQLITE_URL_PREFIX
from homeassistant.components.recorder.models import RecorderRuns
from homeassistant.components.recorder.util import end_incomplete_runs, session_scope
from homeassistant.components.recorder.util import (
end_incomplete_runs,
is_second_sunday,
session_scope,
)
from homeassistant.util import dt as dt_util
from .common import corrupt_db_file
@ -584,3 +588,14 @@ async def test_write_lock_db(hass, tmp_path):
# would be allowed to proceed as the goal is to prevent
# all the other threads from accessing the database
await hass.async_add_executor_job(_drop_table)
def test_is_second_sunday():
"""Test we can find the second sunday of the month."""
assert is_second_sunday(datetime(2022, 1, 9, 0, 0, 0, tzinfo=dt_util.UTC)) is True
assert is_second_sunday(datetime(2022, 2, 13, 0, 0, 0, tzinfo=dt_util.UTC)) is True
assert is_second_sunday(datetime(2022, 3, 13, 0, 0, 0, tzinfo=dt_util.UTC)) is True
assert is_second_sunday(datetime(2022, 4, 10, 0, 0, 0, tzinfo=dt_util.UTC)) is True
assert is_second_sunday(datetime(2022, 5, 8, 0, 0, 0, tzinfo=dt_util.UTC)) is True
assert is_second_sunday(datetime(2022, 1, 10, 0, 0, 0, tzinfo=dt_util.UTC)) is False