1818
1919from testcontainers .core .generic import DbContainer
2020from 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
2424class 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