[Bug]: WaitStrategyTarget Handles Multiple Ports Differently to Documentation

未關閉 適合新手
#12,196 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@suvvvv 已經在處理了。

開始於 2026年12月1日。

  • #12197 來自 @suvvvv —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
68/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
docker, java
領域
testing-qa

研究方向

首先查看 WaitStrategyTarget.getLivenessCheckPortNumbers() 以及它如何排序對應的容器連接埠,然後檢視針對公開多個連接埠之容器的 HTTP 等待策略測試。重現間歇性選擇的問題,並確認修正一律以第一個對應的連接埠為目標,同時新增涵蓋兩個公開連接埠的回歸測試。

由索引模型根據 Issue 內容生成。

描述

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

主要語言
Java
星號
8.8k
分支
2k
平均合併
2 天 1 小時
30 天內合併 PR
11

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

testcontainers/testcontainers-java 的其他 Issue

查看 testcontainers/testcontainers-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。