testcontainers / testcontainers/testcontainers-python
Question: Cannot start KafkaContainer() (on windows(?))
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 2.3k
- Fork
- 386
- Merge trung bình
- 4 giờ 40 phút
- Pull request đã merge (30 ngày)
- 1
Mô tả
I am trying to create a KafkaContainer for my integration test, but I have issues starting it.
Using testcontainers==4.12.0, the following snippet has no issues:
from testcontainers.kafka import KafkaContainer
kafka_container = KafkaContainer()
kafka_container.start()
kafka_bootstrap_servers = cls.kafka_container.get_bootstrap_server()
However, upgrading to testcontainers==4.14.2, the same snippet gives the following issue:
Traceback (most recent call last):
File "...\test.py", line 42, in setUpClass
cls.kafka_container.start()
File "...\env\Lib\site-packages\testcontainers\kafka\__init__.py", line 192, in start
self.tc_start()
File "...\env\Lib\site-packages\testcontainers\kafka\__init__.py", line 165, in tc_start
port = self.get_exposed_port(self.port)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\env\Lib\site-packages\testcontainers\core\container.py", line 251, in get_exposed_port
return self._get_exposed_port(port)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\env\Lib\site-packages\testcontainers\core\container.py", line 257, in _get_exposed_port
return int(self.get_docker_client().port(c.id, port))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\env\Lib\site-packages\testcontainers\core\docker_client.py", line 170, in port
raise ConnectionError(f"Port mapping for container {container_id} and port {port} is not available")
ConnectionError: Port mapping for container 06001694f7ed34dac7f89c4f3a3488d23a884338ec2cc8b367120c2452d39382 and port 9093 is not available
I did a simple investigation and found out that the waiting logic has changed between these two tags. When I use tag 13.0 and 13.1, there is a "legacy deprecation warning" but KafkaContainer can still be started.
...\test.py:40: DeprecationWarning: The wait_for_logs function with string or callable predicates is deprecated and will be removed in a future version. Use structured wait strategies instead: container.waiting_for(LogMessageWaitStrategy('ready')) or container.waiting_for(LogMessageWaitStrategy(re.compile(r'pattern')))
wait_for_logs(cls.kafka_container, "started")
Specifically, the ConnectionError I mentioned above occurred when I upgraded 13.1 to 13.2. The changes I suspect could cause this would be this line
Not sure if this is caused by wrong usage of the library or my personal setup. It is worth noting that I have to disable Ryuk when running the code snippet (using TESTCONTAINERS_RYUK_DISABLED=true) and I am running the code snippet from Windows cmd.
Let me know if there are more information I could provide to investigate this further
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với testcontainers/kafka/init.py và testcontainers/core/docker_client.py, tập trung vào các thay đổi về việc chờ và ánh xạ cổng giữa v4.13.1 và v4.13.2. Tái hiện đoạn mã KafkaContainer được cung cấp trên Windows với Ryuk bị vô hiệu hóa, sau đó xác minh rằng container khởi động và get_bootstrap_server() trả về một endpoint có thể sử dụng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- docker, kafka, python
- Lĩnh vực
- devops, testing-qa
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 48/100