fix: Allow passing in a custom wait strategy string in MySQL, Cassandra, Kafka and Trino by SubhadityaMukherjee · Pull Request #953 · testcontainers/testcontainers-python · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions modules/cassandra/testcontainers/cassandra/__init__.py
10 changes: 8 additions & 2 deletions modules/kafka/testcontainers/kafka/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,18 @@ class KafkaContainer(DockerContainer):
TC_START_SCRIPT = "/tc-start.sh"
MIN_KRAFT_TAG = "7.0.0"

def __init__(self, image: str = "confluentinc/cp-kafka:7.6.0", port: int = 9093, **kwargs) -> None:
def __init__(
self,
image: str = "confluentinc/cp-kafka:7.6.0",
port: int = 9093,
wait_strategy_check_string: str = r".*\[KafkaServer id=\d+\] started.*",
**kwargs,
) -> None:
raise_for_deprecated_parameter(kwargs, "port_to_expose", "port")
super().__init__(image, **kwargs)
self.port = port
self.kraft_enabled = False
self.wait_for: re.Pattern[str] = re.compile(r".*\[KafkaServer id=\d+\] started.*")
self.wait_for: re.Pattern[str] = re.compile(wait_strategy_check_string)
self.boot_command = ""
self.cluster_id = "MkU3OEVBNTcwNTJENDM2Qk"
self.listeners = f"PLAINTEXT://0.0.0.0:{self.port},BROKER://0.0.0.0:9092"
Expand Down
4 changes: 3 additions & 1 deletion modules/mysql/testcontainers/mysql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(
dbname: Optional[str] = None,
port: int = 3306,
seed: Optional[str] = None,
wait_strategy_check_string: str = r".*: ready for connections.*: ready for connections.*",
**kwargs,
) -> None:
if dialect is not None and dialect.startswith("mysql+"):
Expand All @@ -96,6 +97,7 @@ def __init__(
if self.username == "root":
self.root_password = self.password
self.seed = seed
self.wait_strategy_check_string = wait_strategy_check_string

def _configure(self) -> None:
self.with_env("MYSQL_ROOT_PASSWORD", self.root_password)
Expand All @@ -107,7 +109,7 @@ def _configure(self) -> None:

def _connect(self) -> None:
wait_strategy = LogMessageWaitStrategy(
re.compile(r".*: ready for connections.*: ready for connections.*", flags=re.DOTALL | re.MULTILINE),
re.compile(self.wait_strategy_check_string, flags=re.DOTALL | re.MULTILINE),
)
wait_strategy.wait_until_ready(self)

Expand Down
3 changes: 2 additions & 1 deletion modules/trino/testcontainers/trino/__init__.py
Loading