diff --git a/backend/tests/integration/conftest.py b/backend/tests/integration/conftest.py index 69ed6ce..fcaa3c0 100644 --- a/backend/tests/integration/conftest.py +++ b/backend/tests/integration/conftest.py @@ -188,11 +188,13 @@ async def admin_session(admin_engine) -> AsyncGenerator[AsyncSession, None]: yield session finally: try: + # Rollback any failed transaction before cleanup + await session.rollback() if existing_tables: await session.execute(text(f"TRUNCATE {tables_csv} CASCADE")) await session.commit() - except RuntimeError: - pass # Event loop may be closed during final teardown + except (RuntimeError, Exception): + pass # Event loop may be closed or session in bad state await session.close() diff --git a/backend/tests/integration/test_monitoring_api.py b/backend/tests/integration/test_monitoring_api.py index 263818e..fc71fa8 100644 --- a/backend/tests/integration/test_monitoring_api.py +++ b/backend/tests/integration/test_monitoring_api.py @@ -78,13 +78,14 @@ class TestHealthMetrics: await admin_session.execute( text( "INSERT INTO health_metrics " - "(device_id, time, cpu_load, free_memory, total_memory, " + "(device_id, tenant_id, time, cpu_load, free_memory, total_memory, " "free_disk, total_disk, temperature) " - "VALUES (:device_id, :ts, :cpu, :free_mem, :total_mem, " + "VALUES (:device_id, :tenant_id, :ts, :cpu, :free_mem, :total_mem, " ":free_disk, :total_disk, :temp)" ), { "device_id": str(device.id), + "tenant_id": str(tenant.id), "ts": ts, "cpu": 30 + i * 5, "free_mem": 500000000,