Skip to content

Commit

Permalink
Use log waiting strategy for mysql module
Browse files Browse the repository at this point in the history
  • Loading branch information
santi committed Apr 3, 2024
1 parent 0fb4aef commit 68de4ba
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions modules/mysql/testcontainers/mysql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import re
from os import environ
from typing import Optional

from testcontainers.core.generic import DbContainer
from testcontainers.core.utils import raise_for_deprecated_parameter
from testcontainers.core.waiting_utils import wait_for_logs


class MySqlContainer(DbContainer):
Expand Down Expand Up @@ -74,6 +76,12 @@ def _configure(self) -> None:
self.with_env("MYSQL_USER", self.username)
self.with_env("MYSQL_PASSWORD", self.password)

def _connect(self) -> None:
wait_for_logs(
self,
re.compile(".*: ready for connections.*: ready for connections.*", flags=re.DOTALL | re.MULTILINE).search,
)

def get_connection_url(self) -> str:
return super()._create_connection_url(
dialect="mysql+pymysql", username=self.username, password=self.password, dbname=self.dbname, port=self.port
Expand Down

0 comments on commit 68de4ba

Please sign in to comment.