From 9a11f5788fae731ee78c7c9ad30d3f432a4415b4 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 14 Oct 2026 21:45:59 -0400 Subject: [PATCH] test(host_agent): both sensor refreshes run in one event loop (#5786) The second asyncio.run got a pooled connection bound to the first loop. Co-Authored-By: Claude Opus 5.5 --- tests/integration/test_host_metrics.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/integration/test_host_metrics.py b/tests/integration/test_host_metrics.py index bf1330e..7a9ee59 100644 --- a/tests/integration/test_host_metrics.py +++ b/tests/integration/test_host_metrics.py @@ -206,18 +206,16 @@ def test_sensors_are_judged_from_raw_hours_and_rollups_together(app): recorded_at=at.replace(minute=m))) s.add(PluginMetricLatest(source_module="host_agent", resource_name=res, metric_name="temp_c", value=f(99), recorded_at=now)) - return await sensors.refresh(s, now) + first = await sensors.refresh(s, now) + read_from = sensors._read_from + # The next hour reads only the hour the last read ended in; one + # event loop, since the engine's pooled connections belong to it. + return first, read_from, await sensors.refresh(s, now + timedelta(hours=1)) sensors._hours.clear() sensors._read_from = None - got = asyncio.run(_go()) + got, read_from, again = asyncio.run(_go()) assert list(got[host]) == ["SYSTIN"] assert got[host]["SYSTIN"].startswith("falls as the CPU warms (r -1.00 over 100 h") - - async def _again(): # the next hour reads only the hour it ended in - async with app.db_sessionmaker() as s: - return await sensors.refresh(s, now + timedelta(hours=1)) - - assert sensors._read_from == now.replace(minute=0) - again = asyncio.run(_again()) + assert read_from == now.replace(minute=0) assert again[host]["SYSTIN"].startswith("falls as the CPU warms (r -1.00 over 100 h")