[Enhancement]: Document why singleton containers are required under Spring's test context caching
Maintainer antworten meist innerhalb von 2 Tagen
Bewertung
- Schwierigkeit
- 1/5
- Geschätzter Aufwand
- Unter einer Stunde
- Anfängerfreundlichkeit
- 85/100
- Issue-Typ
- Dokumentation
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Ruhig
- Bereich
- documentation, testing
Rechercherichtung
Beginne mit dem Abschnitt "Singleton containers" in Manual container lifecycle control und vergleiche ihn mit der Dokumentation zu @Testcontainers und @Container auf der JUnit 5-Seite. Füge eine kurze Notiz hinzu, die erklärt, warum Container unter @SpringBootTest den Spring context cache überleben müssen und warum das Muster mit dem static initializer beim JVM exit auf Ryuk angewiesen ist; die Dokumentation ist fertig, wenn das class-to-class failure scenario und die Begründung klar sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Java
- Sterne
- 8.7k
- Forks
- 1.9k
- Ø Merge
- 1 T. 5 Std.
- Gemergte PRs (30 T.)
- 1
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Enthält ein Dockerfile oder eine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus testcontainers/testcontainers-java
-
[Bug]: Build fails with "Unknown cli flag: --scripts-prepend-node-path" due to outdated Spotless pluginEvtl. vergeben @dhruv9b hat das vor 43 Tagen übernommen. Offentype/bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
testcontainers/testcontainers-java#11997 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
[Bug]: Cannot reuse Selenium BrowserWebDriverContainers under LinuxEvtl. vergeben @kdelay hat das vor 82 Tagen übernommen. Offentype/bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
testcontainers/testcontainers-java#11941 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
[Bug]: DockerDesktopClientProviderStrategy is always applicableEvtl. vergeben @seonwooj0810 hat das vor 131 Tagen übernommen. Offentype/bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
testcontainers/testcontainers-java#11829 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
[Enhancement]: cleanup document after removing junit4 supportEvtl. vergeben @SJvaca30 hat das vor 138 Tagen übernommen. Offentype/enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
testcontainers/testcontainers-java#11578 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
[Feature]: Presto Module uses the outdated Docker Image of `ghcr.io/trinodb/presto` and needs to be updated to `prestodb/presto`Evtl. vergeben @linghengqian hat das vor 821 Tagen übernommen. Offenhelp wanted type/feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
testcontainers/testcontainers-java#8657 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in testcontainers/testcontainers-java
Ähnliche Issues
-
:ml/Transform >bug Team:ML
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 64/100
elastic/elasticsearch#161960 · 2 Kommentare · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
Maintainer antworten meist innerhalb von 4 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
objectionary/lints#1556 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
wildfly/wildfly-launcher#99 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
apache/rocketmq#11427 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag