[Bug]: WaitStrategyTarget Handles Multiple Ports Differently to Documentation
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 68/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- docker, java
- 领域
- testing-qa
调研方向
首先查看 WaitStrategyTarget.getLivenessCheckPortNumbers() 以及它如何对已映射的容器端口进行排序,然后审查针对公开多个端口的容器的 HTTP 等待策略测试。复现间歇性选择问题,并确认修复始终针对第一个已映射的端口,同时添加覆盖两个公开端口的回归测试。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- Java
- 星标
- 8.8k
- 派生
- 2k
- 平均合并
- 2 天 1 小时
- 30 天内合并 PR
- 11
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
testcontainers/testcontainers-java 的其他 Issue
-
[Bug]: DockerImageName treats uppercase registry names as repository paths可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
testcontainers/testcontainers-java#12186 · 1 条评论 ·
维护者通常 1 天内回复
-
[Bug]: withStartupTimeout() changes the startup timeout of all containers that use the default wait strategy可能已有人在做 @aymenjamaaoui 于 18 天前认领。 未关闭type/bug
难度 2/5 1-3 小时 新手友好度 64/100
testcontainers/testcontainers-java#12171 · 1 条评论 ·
维护者通常 1 天内回复
-
[Enhancement]: Document why singleton containers are required under Spring's test context caching可能已有人在做 @zakaullah075 于 111 天前认领。 未关闭type/enhancement
难度 1/5 1 小时以内 新手友好度 85/100
testcontainers/testcontainers-java#11967 · 1 条评论 ·
维护者通常 1 天内回复
-
[Bug]: Cannot reuse Selenium BrowserWebDriverContainers under Linux可能已有人在做 @kdelay 于 132 天前认领。 未关闭type/bug
难度 2/5 1-3 小时 新手友好度 78/100
testcontainers/testcontainers-java#11941 ·
维护者通常 1 天内回复
-
[Bug]: DockerDesktopClientProviderStrategy is always applicable可能已有人在做 @seonwooj0810 于 181 天前认领。 未关闭type/bug
难度 2/5 1-3 小时 新手友好度 74/100
testcontainers/testcontainers-java#11829 · 1 条评论 ·
维护者通常 1 天内回复
查看 testcontainers/testcontainers-java 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
good first issue help wanted
难度 2/5 1-3 小时 新手友好度 88/100
erkamyaman/rust-anything#1381 ·
维护者通常 1 天内回复
-
enhancement good first issue
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 80/100
java-native-access/jna#1757 ·