From a37ef48dea14050f6eeddae31ecaa28794ef8266 Mon Sep 17 00:00:00 2001 From: fran-penedo Date: Tue, 11 Mar 2025 13:25:05 +0100 Subject: [PATCH] fix: mongo start waiting forever for old mongo versions Old versions of Mongo, like 3.6, log the message "waiting for connections [...]", with a lowercase 'w', while newer versions log the message with uppercase 'W'. This commit makes the log search when starting the container case insensitive. --- modules/mongodb/testcontainers/mongodb/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/mongodb/testcontainers/mongodb/__init__.py b/modules/mongodb/testcontainers/mongodb/__init__.py index 4a436b195..7ab4e11d4 100644 --- a/modules/mongodb/testcontainers/mongodb/__init__.py +++ b/modules/mongodb/testcontainers/mongodb/__init__.py @@ -11,6 +11,7 @@ # License for the specific language governing permissions and limitations # under the License. import os +import re from typing import Optional from pymongo import MongoClient @@ -77,7 +78,12 @@ def get_connection_url(self) -> str: ) def _connect(self) -> None: - wait_for_logs(self, "Waiting for connections") + 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) def get_connection_client(self) -> MongoClient: return MongoClient(self.get_connection_url())