mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Revert "Fix recorder setup hanging if non live schema migration fails" (#122232)
This commit is contained in:
parent
2b93de1348
commit
436a38c1d2
@ -773,7 +773,6 @@ class Recorder(threading.Thread):
|
|||||||
"Database Migration Failed",
|
"Database Migration Failed",
|
||||||
"recorder_database_migration",
|
"recorder_database_migration",
|
||||||
)
|
)
|
||||||
self.hass.add_job(self._async_startup_failed)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if not database_was_ready:
|
if not database_was_ready:
|
||||||
|
@ -200,14 +200,8 @@ async def test_database_migration_encounters_corruption(
|
|||||||
assert move_away.called
|
assert move_away.called
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
("live_migration", "expected_setup_result"), [(True, True), (False, False)]
|
|
||||||
)
|
|
||||||
async def test_database_migration_encounters_corruption_not_sqlite(
|
async def test_database_migration_encounters_corruption_not_sqlite(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant, async_setup_recorder_instance: RecorderInstanceGenerator
|
||||||
async_setup_recorder_instance: RecorderInstanceGenerator,
|
|
||||||
live_migration: bool,
|
|
||||||
expected_setup_result: bool,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test we fail on database error when we cannot recover."""
|
"""Test we fail on database error when we cannot recover."""
|
||||||
assert recorder.util.async_migration_in_progress(hass) is False
|
assert recorder.util.async_migration_in_progress(hass) is False
|
||||||
@ -232,14 +226,8 @@ async def test_database_migration_encounters_corruption_not_sqlite(
|
|||||||
"homeassistant.components.persistent_notification.dismiss",
|
"homeassistant.components.persistent_notification.dismiss",
|
||||||
side_effect=pn.dismiss,
|
side_effect=pn.dismiss,
|
||||||
) as mock_dismiss,
|
) as mock_dismiss,
|
||||||
patch(
|
|
||||||
"homeassistant.components.recorder.core.migration.live_migration",
|
|
||||||
return_value=live_migration,
|
|
||||||
),
|
|
||||||
):
|
):
|
||||||
await async_setup_recorder_instance(
|
await async_setup_recorder_instance(hass, wait_recorder=False)
|
||||||
hass, wait_recorder=False, expected_setup_result=expected_setup_result
|
|
||||||
)
|
|
||||||
hass.states.async_set("my.entity", "on", {})
|
hass.states.async_set("my.entity", "on", {})
|
||||||
hass.states.async_set("my.entity", "off", {})
|
hass.states.async_set("my.entity", "off", {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -1394,8 +1394,6 @@ async def _async_init_recorder_component(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
add_config: dict[str, Any] | None = None,
|
add_config: dict[str, Any] | None = None,
|
||||||
db_url: str | None = None,
|
db_url: str | None = None,
|
||||||
*,
|
|
||||||
expected_setup_result: bool,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the recorder asynchronously."""
|
"""Initialize the recorder asynchronously."""
|
||||||
# pylint: disable-next=import-outside-toplevel
|
# pylint: disable-next=import-outside-toplevel
|
||||||
@ -1410,13 +1408,10 @@ async def _async_init_recorder_component(
|
|||||||
with patch("homeassistant.components.recorder.ALLOW_IN_MEMORY_DB", True):
|
with patch("homeassistant.components.recorder.ALLOW_IN_MEMORY_DB", True):
|
||||||
if recorder.DOMAIN not in hass.data:
|
if recorder.DOMAIN not in hass.data:
|
||||||
recorder_helper.async_initialize_recorder(hass)
|
recorder_helper.async_initialize_recorder(hass)
|
||||||
setup_task = asyncio.ensure_future(
|
assert await async_setup_component(
|
||||||
async_setup_component(hass, recorder.DOMAIN, {recorder.DOMAIN: config})
|
hass, recorder.DOMAIN, {recorder.DOMAIN: config}
|
||||||
)
|
)
|
||||||
# Wait for recorder integration to setup
|
assert recorder.DOMAIN in hass.config.components
|
||||||
setup_result = await setup_task
|
|
||||||
assert setup_result == expected_setup_result
|
|
||||||
assert (recorder.DOMAIN in hass.config.components) == expected_setup_result
|
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
"Test recorder successfully started, database location: %s",
|
"Test recorder successfully started, database location: %s",
|
||||||
config[recorder.CONF_DB_URL],
|
config[recorder.CONF_DB_URL],
|
||||||
@ -1532,16 +1527,10 @@ async def async_test_recorder(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config: ConfigType | None = None,
|
config: ConfigType | None = None,
|
||||||
*,
|
*,
|
||||||
expected_setup_result: bool = True,
|
|
||||||
wait_recorder: bool = True,
|
wait_recorder: bool = True,
|
||||||
) -> AsyncGenerator[recorder.Recorder]:
|
) -> AsyncGenerator[recorder.Recorder]:
|
||||||
"""Setup and return recorder instance.""" # noqa: D401
|
"""Setup and return recorder instance.""" # noqa: D401
|
||||||
await _async_init_recorder_component(
|
await _async_init_recorder_component(hass, config, recorder_db_url)
|
||||||
hass,
|
|
||||||
config,
|
|
||||||
recorder_db_url,
|
|
||||||
expected_setup_result=expected_setup_result,
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
instance = hass.data[recorder.DATA_INSTANCE]
|
instance = hass.data[recorder.DATA_INSTANCE]
|
||||||
# The recorder's worker is not started until Home Assistant is running
|
# The recorder's worker is not started until Home Assistant is running
|
||||||
@ -1568,18 +1557,12 @@ async def async_setup_recorder_instance(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config: ConfigType | None = None,
|
config: ConfigType | None = None,
|
||||||
*,
|
*,
|
||||||
expected_setup_result: bool = True,
|
|
||||||
wait_recorder: bool = True,
|
wait_recorder: bool = True,
|
||||||
) -> AsyncGenerator[recorder.Recorder]:
|
) -> AsyncGenerator[recorder.Recorder]:
|
||||||
"""Set up and return recorder instance."""
|
"""Set up and return recorder instance."""
|
||||||
|
|
||||||
return await stack.enter_async_context(
|
return await stack.enter_async_context(
|
||||||
async_test_recorder(
|
async_test_recorder(hass, config, wait_recorder=wait_recorder)
|
||||||
hass,
|
|
||||||
config,
|
|
||||||
expected_setup_result=expected_setup_result,
|
|
||||||
wait_recorder=wait_recorder,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
yield async_setup_recorder
|
yield async_setup_recorder
|
||||||
|
Loading…
x
Reference in New Issue
Block a user