testcontainers / testcontainers/testcontainers-java

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

Đang mở
#302 4 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

resolution/acknowledged resolution/somedaymaybe type/breaking-api-change
Ngôn ngữ chính
Java
Star
8.7k
Fork
1.9k
Merge trung bình
2 ngày 17 giờ
Pull request đã merge (30 ngày)
9

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Đọc core/src/main/java/org/testcontainers/containers/GenericContainer.java xung quanh constructor và các entry point setDockerImageName(), getDockerImageName() và start(). Xác minh rằng việc tạo container không liên hệ với remote registry, trong khi quá trình khởi động vẫn resolve image; xác nhận hành vi này bằng các bài kiểm thử container hiện có liên quan.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
docker, java
Lĩnh vực
testing
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.