Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
342ee3a
Skip db locking test with postgresql/MySQL
bdraco Feb 9, 2023
dc3a7b3
Turn back off test_shutdown_before_startup_finishes on MySQL
bdraco Feb 9, 2023
0005e89
switch to the guards instead
bdraco Feb 9, 2023
57e16da
Merge branch 'test_shutdown_before_startup_finishes_mysql' into ii
bdraco Feb 9, 2023
30c3637
Disable test_migration_in_progress on MySQL
bdraco Feb 9, 2023
3d3310e
Merge branch 'disable_test_migration_in_progress' into ii
bdraco Feb 9, 2023
d6d5848
Disable test_entity_ids on MariaDB
bdraco Feb 9, 2023
a3ddbe2
Merge branch 'test_entity_ids_innodb_deadlock' into ii
bdraco Feb 9, 2023
8cdea7c
better fix, close stale connections
bdraco Feb 9, 2023
a5ec73d
Update tests/components/recorder/test_init.py
bdraco Feb 9, 2023
c97a053
Merge branch 'dev' into ii
epenet Feb 9, 2023
8ecf6dd
raise if connections active instead
bdraco Feb 9, 2023
d1a1903
Merge branch 'dev' into ii
bdraco Feb 9, 2023
9cadd9e
Merge remote-tracking branch 'origin/ii' into ii
bdraco Feb 9, 2023
58f63c7
Update tests/conftest.py
bdraco Feb 9, 2023
51f60a1
Update tests/conftest.py
bdraco Feb 9, 2023
43f9518
Update tests/conftest.py
bdraco Feb 9, 2023
fb61803
fix another test
bdraco Feb 9, 2023
fb29081
still dispose
bdraco Feb 9, 2023
a3ada74
fix more tests
bdraco Feb 9, 2023
aeecaf4
Merge remote-tracking branch 'upstream/dev' into ii
bdraco Feb 9, 2023
a9c4fcd
Really ensure recorder test fixture is setup before hass fixture
emontnemery Feb 9, 2023
538ac39
Merge remote-tracking branch 'upstream/recorder_fix_cleanup' into ii
bdraco Feb 9, 2023
5593833
fix run history test
bdraco Feb 9, 2023
a6ddc36
Merge branch 'dev' into ii
bdraco Feb 9, 2023
fc414a6
add missing patch
bdraco Feb 9, 2023
ce60266
Merge remote-tracking branch 'origin/ii' into ii
bdraco Feb 9, 2023
4ed0f8e
comment
bdraco Feb 9, 2023
17323e5
add mocks
bdraco Feb 9, 2023
770a322
Merge branch 'dev' into ii
bdraco Feb 9, 2023
ac64ebc
make sure event session is still closed if the commit fails
bdraco Feb 9, 2023
7b837c8
Merge remote-tracking branch 'origin/ii' into ii
bdraco Feb 9, 2023
7c954a9
Ensure recorder still shuts down if the final commit fails
bdraco Feb 9, 2023
3f21467
do not block event loop
bdraco Feb 9, 2023
0d89e9d
Merge branch 'ensure_recorder_shutdown' into ii
bdraco Feb 9, 2023
7e9ca89
do the session in the executor as well
bdraco Feb 9, 2023
7ae6e20
Merge branch 'ensure_recorder_shutdown' into ii
bdraco Feb 9, 2023
2f4e86b
safer
bdraco Feb 9, 2023
10acbbf
Merge branch 'ensure_recorder_shutdown' into ii
bdraco Feb 9, 2023
7e4a272
Merge branch 'dev' into ii
bdraco Feb 9, 2023
b33e9ca
Update tests/components/recorder/test_init.py
bdraco Feb 9, 2023
0cabe31
Merge branch 'dev' into ii
bdraco Feb 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion tests/components/recorder/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ async def test_shutdown_before_startup_finishes(
tmp_path,
):
"""Test shutdown before recorder starts is clean."""

if recorder_db_url == "sqlite://":
Comment thread
bdraco marked this conversation as resolved.
# On-disk database because this test does not play nice with the
# MutexPool
Expand Down Expand Up @@ -1529,6 +1528,10 @@ async def test_database_lock_and_unlock(
tmp_path,
):
"""Test writing events during lock getting written after unlocking."""
if recorder_db_url.startswith(("mysql://", "postgresql://")):
# Database locking is only used for SQLite
return

if recorder_db_url == "sqlite://":
# Use file DB, in memory DB cannot do write locks.
recorder_db_url = "sqlite:///" + str(tmp_path / "pytest.db")
Expand Down Expand Up @@ -1574,6 +1577,10 @@ async def test_database_lock_and_overflow(
tmp_path,
):
"""Test writing events during lock leading to overflow the queue causes the database to unlock."""
if recorder_db_url.startswith(("mysql://", "postgresql://")):
# Database locking is only used for SQLite
return

# Use file DB, in memory DB cannot do write locks.
if recorder_db_url == "sqlite://":
# Use file DB, in memory DB cannot do write locks.
Expand Down
21 changes: 20 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,26 @@ def _ha_orm_quote(mixed, ident):
assert not sqlalchemy_utils.database_exists(db_url)
sqlalchemy_utils.create_database(db_url, encoding="utf8")
yield db_url
if db_url.startswith("mysql://") or db_url.startswith("postgresql://"):
if db_url.startswith("mysql://"):
import sqlalchemy as sa

made_url = sa.make_url(db_url)
db = made_url.database
engine = sa.create_engine(db_url)
# Kill any open connections to the database before dropping it
Comment thread
bdraco marked this conversation as resolved.
Outdated
# to ensure that InnoDB does not deadlock.
with engine.begin() as connection:
query = sa.text(
"select id FROM information_schema.processlist WHERE db=:db and id != CONNECTION_ID()"
)
for row in connection.execute(query, parameters={"db": db}).fetchall():
_LOGGER.warning(
"Killing MySQL connection to temporary database %s", row.id
Comment thread
bdraco marked this conversation as resolved.
Outdated
)
connection.execute(sa.text("KILL :id"), parameters={"id": row.id})
engine.dispose()
Comment thread
bdraco marked this conversation as resolved.
sqlalchemy_utils.drop_database(db_url)
elif db_url.startswith("postgresql://"):
sqlalchemy_utils.drop_database(db_url)


Expand Down