providers/mongo: ping mongod before yielding from mongodb_container fixture#67066
Merged
Merged
Conversation
…ixture
Under uv --resolution lowest-direct, testcontainers==4.12.0 is pinned and
MongoDbContainer.start() waits only for the "waiting for connections" log
line. mongod can emit that log line a few milliseconds before the TCP
listener is actually accepting connections on the published port. We
observed a low-frequency ARM CI flake where the entire TestMongoHook
suite errored at setup_method with:
pymongo.errors.ServerSelectionTimeoutError: 172.17.0.1:32769:
[Errno 111] Connection refused
while the same SHA passed on the other parallel runs.
No testcontainers version on PyPI closes the log-to-listener gap for
modern mongo images (4.13.2 only made the log regex case-insensitive for
mongo 3.6); the only reliable fix is to actively probe mongod from the
fixture. Add a short pymongo ping loop after get_connection_url() and
before yielding so all dependent fixtures see a mongod that actually
accepts connections.
jscheffl
approved these changes
May 17, 2026
Member
Author
|
I'd love to get this one merged. Drafted-by: Claude Code (Opus 4.7); reviewed by @potiuk before posting |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
Low dep tests: providersmongo job is occasionally flaky on ARM CI —every
TestMongoHooktest errors atsetup_methodwith:while the same SHA passes on the other parallel runs (e.g. mongo-3.11
failed in run 25978857524
while every other mongo slot on that SHA was green).
Root cause: under
uv --resolution lowest-direct,testcontainersispinned at the floor (
4.12.0).MongoDbContainer.start()only waits forthe
"waiting for connections"log line, and mongod can emit that line afew milliseconds before the TCP listener is actually accepting on the
published port. The fixture yielded
get_connection_url()immediatelyafter
start()returned, so the first hook setup hit a closed port.No testcontainers version on PyPI closes that gap —
testcontainers 4.13.2only made the log regex case-insensitive for legacy mongo 3.6 images
(see testcontainers-python#783),
which doesn't help mongo:8.0. The reliable fix is in our own conftest.
Fix: after
container.start()succeeds, actively ping mongod withpymongo.MongoClient.admin.command("ping")retried for up to 60 s, thenyield. All dependent fixtures now see a mongod that genuinely accepts
connections.
Observed failing CI job: https://github.com/apache/airflow/actions/runs/25978857524/job/76374215829
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Opus 4.7 (1M context) following the guidelines