Fix sql doing I/O in the event loop at startup (#90335)
* Fix sql doing I/O in the event loop * Fix sql doing I/O in the event loop * no test query on main db * fix mocking because it was targeting the recorder
This commit is contained in:
parent
75e28826e0
commit
7098debe09
2 changed files with 46 additions and 23 deletions
|
@ -2,6 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
@ -193,14 +194,19 @@ async def test_invalid_url_on_update(
|
|||
"column": "value",
|
||||
"name": "count_tables",
|
||||
}
|
||||
await init_integration(hass, config)
|
||||
|
||||
class MockSession:
|
||||
"""Mock session."""
|
||||
|
||||
def execute(self, query: Any) -> None:
|
||||
"""Execute the query."""
|
||||
raise SQLAlchemyError("sqlite://homeassistant:hunter2@homeassistant.local")
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.sql.sensor.sqlalchemy.engine.cursor.CursorResult",
|
||||
side_effect=SQLAlchemyError(
|
||||
"sqlite://homeassistant:hunter2@homeassistant.local"
|
||||
),
|
||||
"homeassistant.components.sql.sensor.scoped_session",
|
||||
return_value=MockSession,
|
||||
):
|
||||
await init_integration(hass, config)
|
||||
async_fire_time_changed(
|
||||
hass,
|
||||
dt.utcnow() + timedelta(minutes=1),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue