[Enhancement]: Document why singleton containers are required under Spring's test context caching
維護者通常 2 天內回覆
評估
- 難度
- 1/5
- 預估耗時
- 1 小時以內
- 新手友好度
- 85/100
- Issue 類型
- 文件
- 描述清晰度
- 描述清楚
- 活躍度
- 冷清
- 領域
- documentation, testing
研究方向
從 Manual container lifecycle control 中的 "Singleton containers" 區段開始,並將其與 JUnit 5 頁面上關於 @Testcontainers 和 @Container 的文件進行比較。新增一則簡短說明,解釋為什麼 @SpringBootTest 下的容器必須比 Spring 的 context cache 存活更久,以及為什麼 static-initialiser pattern 依賴 JVM exit 時的 Ryuk;當 class-to-class failure scenario 及其理由清楚明確時,文件就完成了。
由索引模型根據 Issue 內容生成。
描述
Module
Core
Proposal
The gap
The "Singleton containers" section in Manual container lifecycle control shows the static-initialiser pattern, and the JUnit 5 page documents @Testcontainers / @Container. Neither explains the failure that makes the singleton pattern necessary under @SpringBootTest, and the symptom is misleading enough that it costs people real time.
The failure
Spring caches the application context across test classes. @Testcontainers ties container lifecycle to the test class. Those two facts conflict:
- Test class A runs. The container starts. Spring builds a context pointing at the container's mapped port.
- Class A finishes.
@Testcontainersstops the container. - Class B runs. Spring reuses the cached context, still pointing at the container that was just shut down.
- Every test in class B fails with connection errors.
The misleading part is that class A passes and class B fails, and the error mentions nothing about containers. It reads like test pollution or an ordering problem, so that is where people go looking first.
Current documentation
Manual container lifecycle control says only: "Sometimes it might be useful to define a container that is only started once for several test classes." The JUnit 5 page does not mention Spring at all. So the pattern is documented, but the reason for it is not.
Proposal
Add a short note to the Singleton containers section: under @SpringBootTest, container lifecycle has to outlive Spring's context cache. That is why the containers are started in a static initialiser and deliberately never stopped — Ryuk reaps them at JVM exit, so nothing leaks.
I hit this building a Spring Boot project with Postgres and RabbitMQ containers and lost a while to it. Happy to open a PR if you would take it.
- 主要語言
- Java
- 星號
- 8.8k
- 分支
- 1.9k
- 平均合併
- 4 天 1 小時
- 30 天內合併 PR
- 7
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 提供 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
testcontainers/testcontainers-java 的其他 Issue
-
[Bug]: Cannot reuse Selenium BrowserWebDriverContainers under Linux可能已有人在做 @kdelay 於 89 天前認領。 未關閉type/bug
難度 2/5 1-3 小時 新手友好度 78/100
testcontainers/testcontainers-java#11941 ·
維護者通常 2 天內回覆
-
[Bug]: DockerDesktopClientProviderStrategy is always applicable可能已有人在做 @seonwooj0810 於 138 天前認領。 未關閉type/bug
難度 2/5 1-3 小時 新手友好度 74/100
testcontainers/testcontainers-java#11829 · 1 則留言 ·
維護者通常 2 天內回覆
-
[Enhancement]: cleanup document after removing junit4 support可能已有人在做 @SJvaca30 於 146 天前認領。 未關閉type/enhancement
難度 2/5 1-3 小時 新手友好度 65/100
testcontainers/testcontainers-java#11578 ·
維護者通常 2 天內回覆
-
[Feature]: Presto Module uses the outdated Docker Image of `ghcr.io/trinodb/presto` and needs to be updated to `prestodb/presto`可能已有人在做 @linghengqian 於 828 天前認領。 未關閉help wanted type/feature
難度 2/5 1-3 小時 新手友好度 68/100
testcontainers/testcontainers-java#8657 · 4 則留言 ·
維護者通常 2 天內回覆
-
[Bug]: HttpWaitStrategy removes line breaks in http response body before responsePredicate invocation可能已有人在做 @ivankrn 於 94 天前認領。 未關閉resolution/waiting-for-info type/bug
難度 2/5 1-3 小時 新手友好度 68/100
testcontainers/testcontainers-java#7326 · 3 則留言 ·
維護者通常 2 天內回覆
查看 testcontainers/testcontainers-java 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 76/100
-
難度 2/5 1-3 小時 新手友好度 78/100
apache/rocketmq-dashboard#7302 ·
維護者通常 3 天內回覆
-
area: android good first issue help wanted testing
難度 2/5 1-3 小時 新手友好度 75/100
Gautam-aman/ResQNet#56 ·
維護者通常 1 天內回覆
-
documentation hermes-queue
難度 2/5 1-3 小時 新手友好度 72/100
chrisalunlloyd2-sudo/mindpalace#294 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
QuicksilverMC/Argentum#31 ·