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:
J. Nick Koston 2023-03-26 15:02:24 -10:00 committed by GitHub
parent 75e28826e0
commit 7098debe09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 23 deletions

View file

@ -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),