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 d5eea70ce6a Fix flaky mongo provider tests: disable testcontainers 
ryuk reaper in CI (#67882)
d5eea70ce6a is described below

commit d5eea70ce6a16e4e1b5f1605a93a041eb43e258b
Author: Jarek Potiuk <[email protected]>
AuthorDate: Tue Jun 2 13:36:19 2026 +0200

    Fix flaky mongo provider tests: disable testcontainers ryuk reaper in CI 
(#67882)
    
    On long provider / Airflow-compat test runs the session-scoped MongoDB
    testcontainer was being reaped by testcontainers' ryuk before the mongo
    hook tests ran, causing a cascade of 'Connection refused' errors at the
    setup of every TestMongoHook test (container started fine early in the
    session, then vanished by the time the mongo module executed — the dumped
    container logs were empty because it was already gone).
    
    The fixture stops the container explicitly in its finally block and CI
    runners are ephemeral, so ryuk's auto-reaping is unnecessary and harmful
    there. Disable it via TESTCONTAINERS_RYUK_DISABLED before any
    MongoDbContainer is created — but only in CI, so local runs keep ryuk to
    clean up containers left by an interrupted test run.
---
 providers/mongo/tests/conftest.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/providers/mongo/tests/conftest.py 
b/providers/mongo/tests/conftest.py
index ecc94bc2e80..ac557ed39a1 100644
--- a/providers/mongo/tests/conftest.py
+++ b/providers/mongo/tests/conftest.py
@@ -17,12 +17,26 @@
 from __future__ import annotations
 
 import contextlib
+import os
 import time
 
 import pytest
 from pymongo import MongoClient
 from testcontainers.mongodb import MongoDbContainer
 
+# In CI only: disable the testcontainers "ryuk" reaper. Ryuk reaps spawned
+# containers a short time after the controlling connection drops; on long 
provider /
+# Airflow-compat test runs that can reap the session-scoped MongoDB container
+# *before* the mongo tests execute, producing a cascade of "Connection refused"
+# errors at the setup of every TestMongoHook test (the container started fine 
early
+# in the session, then vanished by the time the mongo module ran). The fixture 
stops
+# the container itself (see ``container.stop()`` below) and CI runners are 
ephemeral,
+# so the reaper is unnecessary and harmful there. Locally we keep ryuk enabled 
so an
+# abandoned container from an interrupted run is still cleaned up. Set before 
any
+# ``MongoDbContainer`` is created so testcontainers picks it up.
+if os.environ.get("CI", "").lower() == "true" or 
os.environ.get("GITHUB_ACTIONS", "").lower() == "true":
+    os.environ.setdefault("TESTCONTAINERS_RYUK_DISABLED", "true")
+
 pytest_plugins = "tests_common.pytest_plugin"
 
 # Pinned to a specific major to keep the image tag stable and avoid drifting

Reply via email to