This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 6c61773caaa Make mongo testcontainer fixture resilient to Docker Hub 
flakes (#66154)
6c61773caaa is described below

commit 6c61773caaa50bc514b951df9a9f9e7728b961ea
Author: Jarek Potiuk <[email protected]>
AuthorDate: Thu Apr 30 19:58:59 2026 +0200

    Make mongo testcontainer fixture resilient to Docker Hub flakes (#66154)
    
    A transient Docker Hub auth-server timeout when pulling mongo:latest
    caused all 33 mongo provider unit tests to fail at fixture setup with
    "context deadline exceeded".
    
    - Pin the image to mongo:8.0 instead of :latest so the tag is stable
      and does not re-resolve a moving target on every run.
    - Retry container start up to 3 times with 5s/10s backoff, so a single
      registry-auth blip no longer cascades into 33 setup errors.
---
 providers/mongo/tests/conftest.py | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/providers/mongo/tests/conftest.py 
b/providers/mongo/tests/conftest.py
index c6a2457e991..7f60bd12c8d 100644
--- a/providers/mongo/tests/conftest.py
+++ b/providers/mongo/tests/conftest.py
@@ -16,13 +16,41 @@
 # under the License.
 from __future__ import annotations
 
+import time
+
 import pytest
 from testcontainers.mongodb import MongoDbContainer
 
 pytest_plugins = "tests_common.pytest_plugin"
 
+# Pinned to a specific major to keep the image tag stable and avoid drifting
+# under us when Docker Hub re-resolves :latest on every run.
+MONGO_IMAGE = "mongo:8.0"
+
 
 @pytest.fixture(scope="session")
 def mongodb_container():
-    with MongoDbContainer("mongo:latest") as mongo:
-        yield mongo.get_connection_url()
+    # Retry container start to absorb transient Docker Hub failures (e.g.
+    # registry-auth timeouts) so a single registry blip does not cascade
+    # into setup errors across the whole mongo test suite.
+    last_exc: Exception | None = None
+    for attempt in range(3):
+        container = MongoDbContainer(MONGO_IMAGE)
+        try:
+            container.start()
+        except Exception as exc:
+            last_exc = exc
+            try:
+                container.stop()
+            except Exception:
+                pass
+            if attempt < 2:
+                time.sleep(5 * (attempt + 1))
+                continue
+            raise
+        try:
+            yield container.get_connection_url()
+        finally:
+            container.stop()
+        return
+    raise last_exc  # pragma: no cover

Reply via email to