mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Avoid locking the database for non-SQLite backends (#63847)
* Avoid locking the database for non-SQLite backends Currently we only have a lock implementation for SQLite. Just return success for all other databases as they are not expected to store data in the config directory and the caller can assume that a backup can be safely taken. This fixes `RuntimeError: generator didn't yield` errors when creating a backup with the current Supervisor dev builds.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
import sqlite3
|
||||
import threading
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@@ -1204,12 +1205,34 @@ async def test_database_lock_timeout(hass):
|
||||
"""Test locking database timeout when recorder stopped."""
|
||||
await async_init_recorder_component(hass)
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
instance: Recorder = hass.data[DATA_INSTANCE]
|
||||
|
||||
class BlockQueue(recorder.RecorderTask):
|
||||
event: threading.Event = threading.Event()
|
||||
|
||||
def run(self, instance: Recorder) -> None:
|
||||
self.event.wait()
|
||||
|
||||
block_task = BlockQueue()
|
||||
instance.queue.put(block_task)
|
||||
with patch.object(recorder, "DB_LOCK_TIMEOUT", 0.1):
|
||||
try:
|
||||
with pytest.raises(TimeoutError):
|
||||
await instance.lock_database()
|
||||
finally:
|
||||
instance.unlock_database()
|
||||
block_task.event.set()
|
||||
|
||||
|
||||
async def test_database_lock_without_instance(hass):
|
||||
"""Test database lock doesn't fail if instance is not initialized."""
|
||||
await async_init_recorder_component(hass)
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||
|
||||
instance: Recorder = hass.data[DATA_INSTANCE]
|
||||
with patch.object(instance, "engine", None):
|
||||
try:
|
||||
assert await instance.lock_database()
|
||||
finally:
|
||||
assert instance.unlock_database()
|
||||
|
||||
Reference in New Issue
Block a user