Skip to content

Commit 7d55384

Browse files
committed
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
1 parent c785ecd commit 7d55384

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

modules/mongodb/testcontainers/mongodb/__init__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from testcontainers.core.generic import DbContainer
2020
from testcontainers.core.utils import raise_for_deprecated_parameter
21-
from testcontainers.core.waiting_utils import wait_for_logs
21+
from testcontainers.core.wait_strategies import LogMessageWaitStrategy
2222

2323

2424
class MongoDbContainer(DbContainer):
@@ -57,7 +57,13 @@ def __init__(
5757
**kwargs,
5858
) -> None:
5959
raise_for_deprecated_parameter(kwargs, "port_to_expose", "port")
60-
super().__init__(image=image, **kwargs)
60+
super().__init__(
61+
image=image,
62+
_wait_strategy=LogMessageWaitStrategy(
63+
re.compile(r"waiting for connections", re.IGNORECASE)
64+
),
65+
**kwargs,
66+
)
6167
self.username = username if username else os.environ.get("MONGO_INITDB_ROOT_USERNAME", "test")
6268
self.password = password if password else os.environ.get("MONGO_INITDB_ROOT_PASSWORD", "test")
6369
self.dbname = dbname if dbname else os.environ.get("MONGO_DB", "test")
@@ -78,12 +84,8 @@ def get_connection_url(self) -> str:
7884
)
7985

8086
def _connect(self) -> None:
81-
regex = re.compile(r"waiting for connections", re.MULTILINE | re.IGNORECASE)
82-
83-
def predicate(text: str) -> bool:
84-
return regex.search(text) is not None
85-
86-
wait_for_logs(self, predicate)
87+
# LogMessageWaitStrategy handles waiting for container readiness
88+
pass
8789

8890
def get_connection_client(self) -> MongoClient:
8991
return MongoClient(self.get_connection_url())

0 commit comments

Comments
 (0)