mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 01:38:02 +00:00
Improve recorder schema migration error test (#134518)
This commit is contained in:
parent
c901352bef
commit
0bd22eabc7
@ -9,7 +9,7 @@ import sqlite3
|
|||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
from unittest.mock import MagicMock, Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
import pytest
|
import pytest
|
||||||
@ -2575,23 +2575,25 @@ async def test_clean_shutdown_when_recorder_thread_raises_during_validate_db_sch
|
|||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("func_to_patch", "expected_setup_result"),
|
("func_to_patch", "expected_setup_result"),
|
||||||
[("migrate_schema_non_live", False), ("migrate_schema_live", False)],
|
[
|
||||||
|
("migrate_schema_non_live", False),
|
||||||
|
("migrate_schema_live", True),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
async def test_clean_shutdown_when_schema_migration_fails(
|
async def test_clean_shutdown_when_schema_migration_fails(
|
||||||
hass: HomeAssistant, func_to_patch: str, expected_setup_result: bool
|
hass: HomeAssistant,
|
||||||
|
func_to_patch: str,
|
||||||
|
expected_setup_result: bool,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test we still shutdown cleanly when schema migration fails."""
|
"""Test we still shutdown cleanly when schema migration fails."""
|
||||||
with (
|
with (
|
||||||
patch.object(
|
patch.object(migration, "_get_current_schema_version", side_effect=[None, 1]),
|
||||||
migration,
|
|
||||||
"validate_db_schema",
|
|
||||||
return_value=MagicMock(valid=False, current_version=1),
|
|
||||||
),
|
|
||||||
patch("homeassistant.components.recorder.ALLOW_IN_MEMORY_DB", True),
|
patch("homeassistant.components.recorder.ALLOW_IN_MEMORY_DB", True),
|
||||||
patch.object(
|
patch.object(
|
||||||
migration,
|
migration,
|
||||||
func_to_patch,
|
func_to_patch,
|
||||||
side_effect=Exception,
|
side_effect=Exception("Boom!"),
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
if recorder.DOMAIN not in hass.data:
|
if recorder.DOMAIN not in hass.data:
|
||||||
@ -2610,9 +2612,13 @@ async def test_clean_shutdown_when_schema_migration_fails(
|
|||||||
assert setup_result == expected_setup_result
|
assert setup_result == expected_setup_result
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
instance = recorder.get_instance(hass)
|
instance = recorder.get_instance(hass)
|
||||||
await hass.async_stop()
|
await hass.async_stop()
|
||||||
assert instance.engine is None
|
assert instance.engine is None
|
||||||
|
|
||||||
|
assert "Error during schema migration" in caplog.text
|
||||||
|
# Check the injected exception was logged
|
||||||
|
assert "Boom!" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_fails_after_downgrade(
|
async def test_setup_fails_after_downgrade(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user