testcontainers / testcontainers/testcontainers-java
GenericContainer tries to talk to remote registry too soon (during instance initialization)
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 8.7k
- Fork
- 1.9k
- Merge medio
- 2g 17h
- PR unite (30g)
- 9
Descrizione
I'm running tests on a machine that doesn't currently have connectivity to the Docker Hub. Certainly, I expect TestContainer-based cases to fail in that case. So I have written a JUnit rule to conditionally disable these test cases when a certain configuration setting has been made, and write something like this in my test case:
public static ConditionalIgnore skip =
ConditionalIgnore.needsDocker(ConfigFactory.load("test"));
// VaultContainer is my own subclass of GenericContainer
public static VaultContainer VAULT = new VaultContainer();
@ClassRule
public static final RuleChain rules = RuleChain.outerRule(skip)
.around(VAULT);
The problem I'm seeing is, however, that this requires instantiating the VaultContainer class, which will call the GenericContainer constructors, and those constructors will actually try to talk to the Docker Hub:
Caused by: org.testcontainers.containers.ContainerFetchException: Can't get Docker image name from org.testcontainers.images.RemoteDockerImage@4a0952ab
at org.testcontainers.containers.GenericContainer.getDockerImageName(GenericContainer.java:711)
at org.testcontainers.containers.GenericContainer.setDockerImageName(GenericContainer.java:699)
at org.testcontainers.containers.GenericContainer.<init>(GenericContainer.java:145)
at com.progressfin.foundation.secret.VaultContainer.<init>(VaultContainer.java:33)
at com.progressfin.foundation.secret.VaultContainer.<init>(VaultContainer.java:29)
at com.progressfin.foundation.secret.VaultSecretsTest.<clinit>(VaultSecretsTest.java:30)
... 40 more
Caused by: org.testcontainers.shaded.com.github.dockerjava.api.exception.InternalServerErrorException: {"message":"Get https://registry-1.docker.io/v2/: read tcp 1.2.3.4:54526->4.3.2.1:443: read: connection reset by peer"}
The problem is here (line numbers don't match up because the stack trace is from 1.1.6):
There's a very interesting comment there ("Mimic old behavior where we resolve image once it's set") that tells us that this behavior is intentional. What I would suggest is that the behavior is at odds with the sort of uses that JUnit rules are meant to support; the test rule should arguably take no "risky" actions at all unless the Statement is actually invoked, i.e. in the GenericContainer.start() method, which already does call the getDockerImageName() method anyway. (And is it just me, or is it also weird that a String getter like getDockerImageName() would talk to the network?)
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Leggi core/src/main/java/org/testcontainers/containers/GenericContainer.java in corrispondenza del costruttore e dei punti di ingresso setDockerImageName(), getDockerImageName() e start(). Verifica che la costruzione di un container non contatti il registry remoto, mentre l’avvio continui a risolvere l’immagine; conferma il comportamento con i test dei container esistenti pertinenti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- docker, java
- Ambito
- testing
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 45/100