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 <noreply@anthropic.com>
This commit is contained in:
@@ -206,18 +206,16 @@ def test_sensors_are_judged_from_raw_hours_and_rollups_together(app):
|
|||||||
recorded_at=at.replace(minute=m)))
|
recorded_at=at.replace(minute=m)))
|
||||||
s.add(PluginMetricLatest(source_module="host_agent", resource_name=res,
|
s.add(PluginMetricLatest(source_module="host_agent", resource_name=res,
|
||||||
metric_name="temp_c", value=f(99), recorded_at=now))
|
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._hours.clear()
|
||||||
sensors._read_from = None
|
sensors._read_from = None
|
||||||
got = asyncio.run(_go())
|
got, read_from, again = asyncio.run(_go())
|
||||||
assert list(got[host]) == ["SYSTIN"]
|
assert list(got[host]) == ["SYSTIN"]
|
||||||
assert got[host]["SYSTIN"].startswith("falls as the CPU warms (r -1.00 over 100 h")
|
assert got[host]["SYSTIN"].startswith("falls as the CPU warms (r -1.00 over 100 h")
|
||||||
|
assert read_from == now.replace(minute=0)
|
||||||
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 again[host]["SYSTIN"].startswith("falls as the CPU warms (r -1.00 over 100 h")
|
assert again[host]["SYSTIN"].startswith("falls as the CPU warms (r -1.00 over 100 h")
|
||||||
|
|||||||
Reference in New Issue
Block a user