Skip to content

Reuse BrowserWebDriverContainer's network for VNC recorder #5617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ tasks.japicmp {
methodExcludes = [
"org.testcontainers.containers.Container#getDockerClient()",
"org.testcontainers.containers.ContainerState#getDockerClient()",
"org.testcontainers.containers.ContainerState#execInContainerWithUser(java.lang.String,java.lang.String[])",
"org.testcontainers.containers.ContainerState#execInContainerWithUser(java.nio.charset.Charset,java.lang.String,java.lang.String[])",
"org.testcontainers.containers.Network#ofContainer(java.lang.String)",
]

fieldExcludes = []
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/org/testcontainers/containers/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.dockerjava.api.command.CreateNetworkCmd;
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.Singular;
import org.junit.rules.ExternalResource;
import org.junit.rules.TestRule;
Expand Down Expand Up @@ -38,6 +39,21 @@ static NetworkImpl.NetworkImplBuilder builder() {
return NetworkImpl.builder();
}

static Network ofContainer(@NonNull String containerId) {
class ContainerNetwork extends ExternalResource implements Network {

@Override
public String getId() {
return "container:" + containerId;
}

@Override
public void close() {}
}

return new ContainerNetwork();
}

@Builder
@Getter
class NetworkImpl extends ExternalResource implements Network {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,6 @@ protected void configure() {
throw new ContainerLaunchException("Exception while trying to create temp directory", e);
}
}

if (getNetwork() == null) {
withNetwork(Network.SHARED);
}

vncRecordingContainer =
new VncRecordingContainer(this)
.withVncPassword(DEFAULT_PASSWORD)
.withVncPort(VNC_PORT)
.withVideoFormat(recordingFormat);
}

if (customImageName != null) {
Expand Down Expand Up @@ -318,8 +308,14 @@ public int getPort() {

@Override
protected void containerIsStarted(InspectContainerResponse containerInfo) {
if (vncRecordingContainer != null) {
if (recordingMode != VncRecordingMode.SKIP) {
LOGGER.debug("Starting VNC recording");
vncRecordingContainer =
new VncRecordingContainer(Network.ofContainer(containerInfo.getId()), "localhost")
.withVncPassword(DEFAULT_PASSWORD)
.withVncPort(VNC_PORT)
.withVideoFormat(recordingFormat);

vncRecordingContainer.start();
}
}
Expand Down