Skip to content

Commit

Permalink
fix: override remote driver default timeouts (#1690)
Browse files Browse the repository at this point in the history
By default remote driver is created with a connection timeout of 2 minutes
and a read timeout of 3 hours. This sometimes causes the validation jobs
to fail with execution timeout, because the remote driver client hangs
because of the 3 hours read timeout.
This change resets the timeout values to be similar to the configuration
used by recent selenium versions.
  • Loading branch information
mcollovati authored Oct 26, 2023
1 parent 77e9450 commit bcee9d4
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
package com.vaadin.testbench.parallel.setup;

import java.net.URL;
import java.time.Duration;
import java.util.HashMap;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.HttpCommandExecutor;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.http.HttpClient;

import com.vaadin.testbench.TestBench;

Expand All @@ -32,8 +36,11 @@ public WebDriver createDriver(String hubURL,
DesiredCapabilities capabilities) throws Exception {
for (int i = 1; i <= BROWSER_INIT_ATTEMPTS; i++) {
try {
HttpClient.Factory httpClientFactory = new HttpClientFactoryDefaultWrapper();
HttpCommandExecutor executor = new HttpCommandExecutor(
new HashMap<>(), new URL(hubURL), httpClientFactory);
WebDriver dr = TestBench.createDriver(
new RemoteWebDriver(new URL(hubURL), capabilities));
new RemoteWebDriver(executor, capabilities));
return dr;
} catch (Exception e) {
System.err.println("Browser startup for " + capabilities
Expand All @@ -47,4 +54,24 @@ public WebDriver createDriver(String hubURL,
// should never happen
return null;
}

// Override the default builder to set timeouts as in newer selenium version
// readTimeout to 3 minutes instead of 3 hours
// connectionTimeout to 10 seconds instead of 2 minutes
private static class HttpClientFactoryDefaultWrapper
implements HttpClient.Factory {
private final HttpClient.Factory delegate = HttpClient.Factory
.createDefault();

@Override
public HttpClient.Builder builder() {
return delegate.builder().connectionTimeout(Duration.ofSeconds(10))
.readTimeout(Duration.ofMinutes(3));
}

@Override
public void cleanupIdleClients() {
delegate.cleanupIdleClients();
}
}
}

0 comments on commit bcee9d4

Please sign in to comment.