|
1 | 1 | import os.path |
| 2 | +import re |
2 | 3 | import tarfile |
3 | 4 | import time |
4 | 5 | from io import BytesIO |
5 | 6 | from textwrap import dedent |
6 | 7 |
|
7 | 8 | from testcontainers.core.container import DockerContainer |
8 | | -from testcontainers.core.waiting_utils import wait_for_logs |
| 9 | +from testcontainers.core.wait_strategies import LogMessageWaitStrategy |
9 | 10 |
|
10 | 11 |
|
11 | 12 | class RedpandaContainer(DockerContainer): |
@@ -34,6 +35,7 @@ def __init__( |
34 | 35 | self.redpanda_port = 9092 |
35 | 36 | self.schema_registry_port = 8081 |
36 | 37 | self.with_exposed_ports(self.redpanda_port, self.schema_registry_port) |
| 38 | + self.wait_for = re.compile(r".*Started Kafka API server.*") |
37 | 39 |
|
38 | 40 | def get_bootstrap_server(self) -> str: |
39 | 41 | host = self.get_container_host_ip() |
@@ -64,13 +66,14 @@ def tc_start(self) -> None: |
64 | 66 |
|
65 | 67 | self.create_file(data, RedpandaContainer.TC_START_SCRIPT) |
66 | 68 |
|
67 | | - def start(self, timeout=10) -> "RedpandaContainer": |
| 69 | + def start(self) -> "RedpandaContainer": |
68 | 70 | script = RedpandaContainer.TC_START_SCRIPT |
69 | 71 | command = f'-c "while [ ! -f {script} ]; do sleep 0.1; done; sh {script}"' |
70 | 72 | self.with_command(command) |
71 | 73 | super().start() |
72 | 74 | 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) |
74 | 77 | return self |
75 | 78 |
|
76 | 79 | def create_file(self, content: bytes, path: str) -> None: |
|
0 commit comments