Skip to content

test: release the first connection before asserting the second reuses it - #23

Merged
AlexeyShalaev merged 1 commit into
masterfrom
fix/flaky-conn-metrics-test
Sep 6, 2026
Merged

test: release the first connection before asserting the second reuses it#23
AlexeyShalaev merged 1 commit into
masterfrom
fix/flaky-conn-metrics-test

Conversation

@AlexeyShalaev

Copy link
Copy Markdown
Member

test__conn_metrics__annotate_the_call_span failed the integration job on the release pull request (#22), asserting http.connection.reused is True on the second call and getting False. The test is two days old — it arrived with the conn_metrics fix in #20 — and it passed on both earlier runs today, so it is a flake rather than a regression.

Why it flakes. The test made two calls and read neither body. aiohttp returns a connection to the pool when the response is released, which for an unread body happens on cleanup rather than at the call site. The second request therefore raced the first one's release: with the file running alone the connection was back in the pool in time and the assertion held; under the whole integration suite it often was not.

Reproduced locally: one failure in two full -m integration runs before the change. After it, three consecutive full runs pass, 174 tests each.

The fix is in the test, not the adapter. Reading each body makes the release ordering explicit instead of leaving it to scheduling. What the test is actually about — that Attempt.conn reaches the call span, that a fresh connection carries a connect duration and a pooled one does not — is unchanged and still asserted.

make check passes, including the three import-linter contracts.

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.
@AlexeyShalaev
AlexeyShalaev merged commit 4022f2b into master Sep 6, 2026
8 checks passed
@AlexeyShalaev
AlexeyShalaev deleted the fix/flaky-conn-metrics-test branch September 6, 2026 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant