From 7d55384a235a5b557f88016b8f3e34c1b5afe92d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Valdemar=20M=C3=B8rch?= Date: Sat, 27 Dec 2025 23:08:27 +0100 Subject: [PATCH] fix(mongodb): Use wait strategy instead of deprecated wait_for_logs Replace the deprecated wait_for_logs function with LogMessageWaitStrategy in the MongoDB container module. Part of fix for #874 --- .../mongodb/testcontainers/mongodb/__init__.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/modules/mongodb/testcontainers/mongodb/__init__.py b/modules/mongodb/testcontainers/mongodb/__init__.py index 7ab4e11d4..b97ae415b 100644 --- a/modules/mongodb/testcontainers/mongodb/__init__.py +++ b/modules/mongodb/testcontainers/mongodb/__init__.py @@ -18,7 +18,7 @@ from testcontainers.core.generic import DbContainer from testcontainers.core.utils import raise_for_deprecated_parameter -from testcontainers.core.waiting_utils import wait_for_logs +from testcontainers.core.wait_strategies import LogMessageWaitStrategy class MongoDbContainer(DbContainer): @@ -57,7 +57,13 @@ def __init__( **kwargs, ) -> None: raise_for_deprecated_parameter(kwargs, "port_to_expose", "port") - super().__init__(image=image, **kwargs) + super().__init__( + image=image, + _wait_strategy=LogMessageWaitStrategy( + re.compile(r"waiting for connections", re.IGNORECASE) + ), + **kwargs, + ) self.username = username if username else os.environ.get("MONGO_INITDB_ROOT_USERNAME", "test") self.password = password if password else os.environ.get("MONGO_INITDB_ROOT_PASSWORD", "test") self.dbname = dbname if dbname else os.environ.get("MONGO_DB", "test") @@ -78,12 +84,8 @@ def get_connection_url(self) -> str: ) def _connect(self) -> None: - regex = re.compile(r"waiting for connections", re.MULTILINE | re.IGNORECASE) - - def predicate(text: str) -> bool: - return regex.search(text) is not None - - wait_for_logs(self, predicate) + # LogMessageWaitStrategy handles waiting for container readiness + pass def get_connection_client(self) -> MongoClient: return MongoClient(self.get_connection_url())