Skip to content

Commit def4e37

Browse files
committed
fix(redpanda): Use wait strategy instead of deprecated wait_for_logs
1 parent 5c1504c commit def4e37

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

modules/kafka/testcontainers/kafka/_redpanda.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import os.path
2+
import re
23
import tarfile
34
import time
45
from io import BytesIO
56
from textwrap import dedent
67

78
from testcontainers.core.container import DockerContainer
8-
from testcontainers.core.waiting_utils import wait_for_logs
9+
from testcontainers.core.wait_strategies import LogMessageWaitStrategy
910

1011

1112
class RedpandaContainer(DockerContainer):
@@ -34,6 +35,7 @@ def __init__(
3435
self.redpanda_port = 9092
3536
self.schema_registry_port = 8081
3637
self.with_exposed_ports(self.redpanda_port, self.schema_registry_port)
38+
self.wait_for = re.compile(r".*Started Kafka API server.*")
3739

3840
def get_bootstrap_server(self) -> str:
3941
host = self.get_container_host_ip()
@@ -64,13 +66,14 @@ def tc_start(self) -> None:
6466

6567
self.create_file(data, RedpandaContainer.TC_START_SCRIPT)
6668

67-
def start(self, timeout=10) -> "RedpandaContainer":
69+
def start(self) -> "RedpandaContainer":
6870
script = RedpandaContainer.TC_START_SCRIPT
6971
command = f'-c "while [ ! -f {script} ]; do sleep 0.1; done; sh {script}"'
7072
self.with_command(command)
7173
super().start()
7274
self.tc_start()
73-
wait_for_logs(self, r".*Started Kafka API server.*", timeout=timeout)
75+
wait_strategy = LogMessageWaitStrategy(self.wait_for)
76+
wait_strategy.wait_until_ready(self)
7477
return self
7578

7679
def create_file(self, content: bytes, path: str) -> None:

0 commit comments

Comments
 (0)