Skip to content

Commit 6e1f8a0

Browse files
authored
Record and dump Ryuk's logs on timeout (#2810)
1 parent 6ac18b2 commit 6e1f8a0

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

core/src/main/java/org/testcontainers/utility/ResourceReaper.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package org.testcontainers.utility;
22

33
import com.github.dockerjava.api.DockerClient;
4+
import com.github.dockerjava.api.async.ResultCallback;
45
import com.github.dockerjava.api.command.InspectContainerResponse;
56
import com.github.dockerjava.api.exception.NotFoundException;
67
import com.github.dockerjava.api.model.Bind;
78
import com.github.dockerjava.api.model.ExposedPort;
9+
import com.github.dockerjava.api.model.Frame;
810
import com.github.dockerjava.api.model.HostConfig;
911
import com.github.dockerjava.api.model.Network;
1012
import com.github.dockerjava.api.model.Ports;
@@ -28,6 +30,7 @@
2830
import java.io.UnsupportedEncodingException;
2931
import java.net.Socket;
3032
import java.net.URLEncoder;
33+
import java.nio.charset.StandardCharsets;
3134
import java.util.AbstractMap.SimpleEntry;
3235
import java.util.ArrayList;
3336
import java.util.Collections;
@@ -93,6 +96,20 @@ public static String start(String hostIpAddress, DockerClient client) {
9396

9497
client.startContainerCmd(ryukContainerId).exec();
9598

99+
StringBuilder ryukLog = new StringBuilder();
100+
101+
client.logContainerCmd(ryukContainerId)
102+
.withSince(0)
103+
.withFollowStream(true)
104+
.withStdOut(true)
105+
.withStdErr(true)
106+
.exec(new ResultCallback.Adapter<Frame>() {
107+
@Override
108+
public void onNext(Frame frame) {
109+
ryukLog.append(new String(frame.getPayload(), StandardCharsets.UTF_8));
110+
}
111+
});
112+
96113
InspectContainerResponse inspectedContainer = client.inspectContainerCmd(ryukContainerId).exec();
97114

98115
Integer ryukPort = inspectedContainer.getNetworkSettings().getPorts().getBindings().values().stream()
@@ -155,7 +172,8 @@ public static String start(String hostIpAddress, DockerClient client) {
155172

156173
// We need to wait before we can start any containers to make sure that we delete them
157174
if (!ryukScheduledLatch.await(TestcontainersConfiguration.getInstance().getRyukTimeout(), TimeUnit.SECONDS)) {
158-
throw new IllegalStateException("Can not connect to Ryuk");
175+
log.error("Timeout out waiting for Ryuk. Ryuk's log:\n{}", ryukLog);
176+
throw new IllegalStateException(String.format("Can not connect to Ryuk at %s:%s", hostIpAddress, ryukPort));
159177
}
160178

161179
return ryukContainerId;

0 commit comments

Comments
 (0)