Improve recorder tests to use MariaDB / PostgreSQL (#87756)
This commit is contained in:
parent
b0f5bdd504
commit
58618b2978
2 changed files with 21 additions and 9 deletions
|
@ -97,14 +97,19 @@ def _default_recorder(hass):
|
||||||
|
|
||||||
|
|
||||||
async def test_shutdown_before_startup_finishes(
|
async def test_shutdown_before_startup_finishes(
|
||||||
async_setup_recorder_instance: SetupRecorderInstanceT, hass: HomeAssistant, tmp_path
|
async_setup_recorder_instance: SetupRecorderInstanceT,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
recorder_db_url: str,
|
||||||
|
tmp_path,
|
||||||
):
|
):
|
||||||
"""Test shutdown before recorder starts is clean."""
|
"""Test shutdown before recorder starts is clean."""
|
||||||
|
|
||||||
# On-disk database because this test does not play nice with the
|
if recorder_db_url == "sqlite://":
|
||||||
# MutexPool
|
# On-disk database because this test does not play nice with the
|
||||||
|
# MutexPool
|
||||||
|
recorder_db_url = "sqlite:///" + str(tmp_path / "pytest.db")
|
||||||
config = {
|
config = {
|
||||||
recorder.CONF_DB_URL: "sqlite:///" + str(tmp_path / "pytest.db"),
|
recorder.CONF_DB_URL: recorder_db_url,
|
||||||
recorder.CONF_COMMIT_INTERVAL: 1,
|
recorder.CONF_COMMIT_INTERVAL: 1,
|
||||||
}
|
}
|
||||||
hass.state = CoreState.not_running
|
hass.state = CoreState.not_running
|
||||||
|
@ -1520,13 +1525,16 @@ def test_entity_id_filter(hass_recorder):
|
||||||
async def test_database_lock_and_unlock(
|
async def test_database_lock_and_unlock(
|
||||||
async_setup_recorder_instance: SetupRecorderInstanceT,
|
async_setup_recorder_instance: SetupRecorderInstanceT,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
recorder_db_url: str,
|
||||||
tmp_path,
|
tmp_path,
|
||||||
):
|
):
|
||||||
"""Test writing events during lock getting written after unlocking."""
|
"""Test writing events during lock getting written after unlocking."""
|
||||||
# Use file DB, in memory DB cannot do write locks.
|
if recorder_db_url == "sqlite://":
|
||||||
|
# Use file DB, in memory DB cannot do write locks.
|
||||||
|
recorder_db_url = "sqlite:///" + str(tmp_path / "pytest.db")
|
||||||
config = {
|
config = {
|
||||||
recorder.CONF_COMMIT_INTERVAL: 0,
|
recorder.CONF_COMMIT_INTERVAL: 0,
|
||||||
recorder.CONF_DB_URL: "sqlite:///" + str(tmp_path / "pytest.db"),
|
recorder.CONF_DB_URL: recorder_db_url,
|
||||||
}
|
}
|
||||||
await async_setup_recorder_instance(hass, config)
|
await async_setup_recorder_instance(hass, config)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -1562,13 +1570,17 @@ async def test_database_lock_and_unlock(
|
||||||
async def test_database_lock_and_overflow(
|
async def test_database_lock_and_overflow(
|
||||||
async_setup_recorder_instance: SetupRecorderInstanceT,
|
async_setup_recorder_instance: SetupRecorderInstanceT,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
recorder_db_url: str,
|
||||||
tmp_path,
|
tmp_path,
|
||||||
):
|
):
|
||||||
"""Test writing events during lock leading to overflow the queue causes the database to unlock."""
|
"""Test writing events during lock leading to overflow the queue causes the database to unlock."""
|
||||||
# Use file DB, in memory DB cannot do write locks.
|
# Use file DB, in memory DB cannot do write locks.
|
||||||
|
if recorder_db_url == "sqlite://":
|
||||||
|
# Use file DB, in memory DB cannot do write locks.
|
||||||
|
recorder_db_url = "sqlite:///" + str(tmp_path / "pytest.db")
|
||||||
config = {
|
config = {
|
||||||
recorder.CONF_COMMIT_INTERVAL: 0,
|
recorder.CONF_COMMIT_INTERVAL: 0,
|
||||||
recorder.CONF_DB_URL: "sqlite:///" + str(tmp_path / "pytest.db"),
|
recorder.CONF_DB_URL: recorder_db_url,
|
||||||
}
|
}
|
||||||
await async_setup_recorder_instance(hass, config)
|
await async_setup_recorder_instance(hass, config)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
|
@ -147,9 +147,9 @@ def test_from_event_to_delete_state() -> None:
|
||||||
assert db_state.last_updated_ts == event.time_fired.timestamp()
|
assert db_state.last_updated_ts == event.time_fired.timestamp()
|
||||||
|
|
||||||
|
|
||||||
def test_entity_ids() -> None:
|
def test_entity_ids(recorder_db_url: str) -> None:
|
||||||
"""Test if entity ids helper method works."""
|
"""Test if entity ids helper method works."""
|
||||||
engine = create_engine("sqlite://")
|
engine = create_engine(recorder_db_url)
|
||||||
Base.metadata.create_all(engine)
|
Base.metadata.create_all(engine)
|
||||||
session_factory = sessionmaker(bind=engine)
|
session_factory = sessionmaker(bind=engine)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue