[Bug]: WaitStrategyTarget Handles Multiple Ports Differently to Documentation

Đang mở Phù hợp với người mới
#12,196 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@suvvvv đang làm issue này rồi.

Từ ngày 1/12/2026.

  • #12197 của @suvvvv — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
docker, java
Lĩnh vực
testing-qa

Hướng nghiên cứu

Bắt đầu với WaitStrategyTarget.getLivenessCheckPortNumbers() và cách phương thức này sắp xếp các cổng container được ánh xạ. Sau đó, xem lại các bài kiểm thử chiến lược chờ HTTP dành cho container có nhiều cổng được expose. Tái hiện việc chọn không ổn định và xác nhận rằng bản sửa luôn nhắm đến cổng được ánh xạ đầu tiên, kèm một bài kiểm thử hồi quy bao phủ hai cổng được expose.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

type/bug
Module

Core

Testcontainers version

2.0.5

Using the latest Testcontainers version?

Yes

Host OS

Linux

Host Arch

x86

Docker version
Client:        Podman Engine
Version:       6.2.1
API Version:   6.2.1
Go Version:    go1.27.4-X:nodwarf5
Git Commit:    3471162efb28760529d852706c493c29245def6d
Built:         Tue Nov 24 00:00:00 2026
Build Origin:  Fedora Project
OS/Arch:       linux/amd64
What happened?

I'm trying to write a test for an application that listens on two ports, one HTTP and one SMTP.

container = new GenericContainer(image)
                .withExposedPorts(8090, 8091)
                .withNetwork(network)
                .withNetworkAliases("archive")
                .waitingFor(Wait.forHttp("/").forStatusCode(200))
                .withStartupTimeout(Duration.ofSeconds(30))

https://java.testcontainers.org/features/startup_and_waits/ says that TestContainers will wait for the first mapped port to be listening on TCP (or run a HTTP healthcheck if one is defined), but I'm seeing my tests intermittently fail to start. From the logs, it seems like TestContainers is alternating between ports to run the test against, failing to start if 8091 gets selected.

Tracing this through, I think the cause is WaitStrategyTarget.getLivenessCheckPortNumbers(). The ports listening on the container are remapped into a Set meaning the order is unpredictable between JVM executions. HashSets are deterministic, but it still means you can get unlucky with which ports get exposed on the container meaning that the wrong one gets picked to healthcheck against.

Relevant log output
2026-12-01T12:07:47.006+0000 INFO /sweet_montalcini: Waiting for 30 seconds for URL: http://localhost:45447/ (where port 45447 maps to container port 8091)
Additional Information

No response

Ngôn ngữ chính
Java
Star
8.8k
Fork
2k
Merge trung bình
2 ngày 1 giờ
Pull request đã merge (30 ngày)
11

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của testcontainers/testcontainers-java

Tất cả issue của testcontainers/testcontainers-java

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.