From fed07349610fb9dfb2a5e3dbed2c171788ee0c4c Mon Sep 17 00:00:00 2001 From: Alexey Shalaev <75322386+AlexeyShalaev@users.noreply.github.com> Date: Sun, 6 Sep 2026 23:25:07 +0300 Subject: [PATCH] test: release the first connection before asserting the second reuses it The connection-metrics test made two calls without reading either body. aiohttp returns a connection to the pool when the response is released, so the second call raced the first one's cleanup: in isolation the first connection was back in time and the assertion held, under the full suite it often was not. It failed the release pull request's integration job, and reproduced locally in one full run out of two. Reading each body makes the release ordering explicit; three consecutive full integration runs pass. --- tests/integration/adapters/test_aiohttp.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/integration/adapters/test_aiohttp.py b/tests/integration/adapters/test_aiohttp.py index 22d9b48..d1353b7 100644 --- a/tests/integration/adapters/test_aiohttp.py +++ b/tests/integration/adapters/test_aiohttp.py @@ -245,8 +245,13 @@ async def test__failure_paths__never_leak_inflight( async def test__conn_metrics__annotate_the_call_span(origin: OriginServer) -> None: tracer = RecordingTracer() client = await build(base_config(origin), AdapterDeps(tracer=tracer)) - await client.get("/echo") - await client.get("/echo") + # Read each body before the next call: aiohttp returns a connection to the + # pool on release, so an unread response leaves the second call racing the + # first one's cleanup for it -- which is how this test used to flake. + first = await client.get("/echo") + await first.read() + second = await client.get("/echo") + await second.read() await client.close() fresh, pooled = (span.attributes for span in tracer.spans) assert fresh["http.connection.connect_duration"] >= 0.0 # TraceConfig timed the handshake