testcontainers / testcontainers/testcontainers-java

GenericContainer tries to talk to remote registry too soon (during instance initialization)

Abierto
#302 4 comentarios 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

resolution/acknowledged resolution/somedaymaybe type/breaking-api-change
Lenguaje dominante
Java
Estrellas
8.7k
Forks
1.9k
Merge medio
2 d 17 h
PR fusionados (30 d)
9

Descripción

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?)

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Lee core/src/main/java/org/testcontainers/containers/GenericContainer.java alrededor del constructor y de los puntos de entrada setDockerImageName(), getDockerImageName() y start(). Verifica que construir un contenedor no se ponga en contacto con el registro remoto, mientras que el inicio siga resolviendo la imagen; confirma el comportamiento con las pruebas de contenedores existentes relevantes.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
docker, java
Área
testing
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.