Skip to content

Commit 87332c1

Browse files
fix(kafka): Use wait strategy instead of deprecated wait_for_logs (#903)
Related to #874. Since those containers first need to be started to know their exposed ports, we cannot use `DockerContainer._wait_strategy`. We have to keep checking logs manually in their own `start` methods. Let me know if there is anything to change. --------- Co-authored-by: Hugo-C <Hugo-C@users.noreply.github.com> Co-authored-by: David Ankin <daveankin@gmail.com>
1 parent 460b0d8 commit 87332c1

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

modules/kafka/testcontainers/kafka/_redpanda.py

Lines changed: 6 additions & 2 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.Pattern[str] = re.compile(r".*Started Kafka API server.*")
3739

3840
def get_bootstrap_server(self) -> str:
3941
host = self.get_container_host_ip()
@@ -70,7 +72,9 @@ def start(self, timeout=10) -> "RedpandaContainer":
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.with_startup_timeout(timeout)
77+
wait_strategy.wait_until_ready(self)
7478
return self
7579

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

modules/kafka/tests/test_redpanda.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_redpanda_producer_consumer():
1313
produce_and_consume_message(container)
1414

1515

16-
@pytest.mark.parametrize("version", ["v23.1.13", "v23.3.10"])
16+
@pytest.mark.parametrize("version", ["v23.1.13", "v25.3.6"])
1717
def test_redpanda_confluent_version(version):
1818
with RedpandaContainer(image=f"docker.redpanda.com/redpandadata/redpanda:{version}") as container:
1919
produce_and_consume_message(container)

0 commit comments

Comments
 (0)