Skip to content
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

[grid] Introduced new variable for server start timeout #15345

Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public class DockerFlags implements HasRoles {
@ConfigValue(section = DockerOptions.DOCKER_SECTION, name = "port", example = "2375")
private Integer dockerPort;

@Parameter(
names = {"--docker-server-start-timeout"},
description = "Max time (in seconds) to wait for the server to successfully start up, before cancelling the process.")
@ConfigValue(section = DockerOptions.DOCKER_SECTION, name = "server-start-timeout", example = "55")
private Integer serverStartTimeout;

@Parameter(
names = {"--docker", "-D"},
description =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.common.collect.Multimap;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -63,6 +64,7 @@ public class DockerOptions {
static final String DEFAULT_DOCKER_URL = "unix:/var/run/docker.sock";
static final String DEFAULT_VIDEO_IMAGE = "false";
static final int DEFAULT_MAX_SESSIONS = Runtime.getRuntime().availableProcessors();
static final int DEFAULT_SERVER_START_TIMEOUT = 60;
private static final String DEFAULT_DOCKER_NETWORK = "bridge";
private static final Logger LOG = Logger.getLogger(DockerOptions.class.getName());
private static final Json JSON = new Json();
Expand Down Expand Up @@ -104,6 +106,10 @@ private URI getDockerUri() {
}
}

private Duration getServerStartTimeout() {
return Duration.ofSeconds(config.getInt(DOCKER_SECTION, "server-start-timeout").orElse(DEFAULT_SERVER_START_TIMEOUT));
}

private boolean isEnabled(Docker docker) {
if (!config.getAll(DOCKER_SECTION, "configs").isPresent()) {
return false;
Expand Down Expand Up @@ -179,6 +185,7 @@ public Map<Capabilities, Collection<SessionFactory>> getDockerSessionFactories(
tracer,
clientFactory,
options.getSessionTimeout(),
getServerStartTimeout(),
docker,
getDockerUri(),
image,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public class DockerSessionFactory implements SessionFactory {
private final Tracer tracer;
private final HttpClient.Factory clientFactory;
private final Duration sessionTimeout;
private final Duration serverStartTimeout;
private final Docker docker;
private final URI dockerUri;
private final Image browserImage;
Expand All @@ -108,6 +109,7 @@ public DockerSessionFactory(
Tracer tracer,
HttpClient.Factory clientFactory,
Duration sessionTimeout,
Duration serverStartTimeout,
Docker docker,
URI dockerUri,
Image browserImage,
Expand All @@ -123,6 +125,7 @@ public DockerSessionFactory(
this.tracer = Require.nonNull("Tracer", tracer);
this.clientFactory = Require.nonNull("HTTP client", clientFactory);
this.sessionTimeout = Require.nonNull("Session timeout", sessionTimeout);
this.serverStartTimeout = Require.nonNull("Server start timeout", serverStartTimeout);
this.docker = Require.nonNull("Docker command", docker);
this.dockerUri = Require.nonNull("Docker URI", dockerUri);
this.browserImage = Require.nonNull("Docker browser image", browserImage);
Expand Down Expand Up @@ -181,7 +184,7 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
"Waiting for server to start (container id: %s, url %s)",
container.getId(), remoteAddress));
try {
waitForServerToStart(client, Duration.ofMinutes(1));
waitForServerToStart(client, serverStartTimeout);
} catch (TimeoutException e) {
span.setAttribute(AttributeKey.ERROR.getKey(), true);
span.setStatus(Status.CANCELLED);
Expand Down Expand Up @@ -367,7 +370,7 @@ private Container startVideoContainer(
clientFactory.createClient(ClientConfig.defaultConfig().baseUri(videoContainerUrl));
try {
LOG.fine(String.format("Waiting for video recording... (id: %s)", videoContainer.getId()));
waitForServerToStart(videoClient, Duration.ofMinutes(1));
waitForServerToStart(videoClient, serverStartTimeout);
} catch (Exception e) {
videoContainer.stop(Duration.ofSeconds(10));
String message =
Expand Down
Loading