Skip to content

Commit 2d3879a

Browse files
authored
[java] Remove max duration value to allow retries
1 parent 3b67ff7 commit 2d3879a

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

‎java/src/org/openqa/selenium/remote/http/RetryRequest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public class RetryRequest implements Filter {
4242
.handleIf(failure -> failure.getCause() instanceof ConnectException)
4343
.withBackoff(1, 4, ChronoUnit.SECONDS)
4444
.withMaxRetries(3)
45-
.withMaxDuration(Duration.ofSeconds(10))
4645
.onRetry(e -> LOG.log(
4746
getDebugLogLevel(),
4847
"Connection failure #{0}. Retrying.",
@@ -54,7 +53,6 @@ public class RetryRequest implements Filter {
5453
.handle(TimeoutException.class)
5554
.withBackoff(1, 4, ChronoUnit.SECONDS)
5655
.withMaxRetries(3)
57-
.withMaxDuration(Duration.ofSeconds(10))
5856
.onRetry(e -> LOG.log(
5957
getDebugLogLevel(),
6058
"Read timeout #{0}. Retrying.",
@@ -68,7 +66,6 @@ public class RetryRequest implements Filter {
6866
.handleResultIf(response -> response.getStatus() == HTTP_UNAVAILABLE)
6967
.withBackoff(1, 2, ChronoUnit.SECONDS)
7068
.withMaxRetries(2)
71-
.withMaxDuration(Duration.ofSeconds(3))
7269
.onRetry(e -> LOG.log(
7370
getDebugLogLevel(),
7471
"Failure due to server error #{0}. Retrying.",

‎java/test/org/openqa/selenium/remote/http/RetryRequestTest.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.google.common.collect.ImmutableMap;
2121
import org.junit.Before;
2222
import org.junit.Test;
23-
import org.openqa.selenium.TimeoutException;
2423
import org.openqa.selenium.environment.webserver.AppServer;
2524
import org.openqa.selenium.environment.webserver.NettyAppServer;
2625
import org.openqa.selenium.remote.http.netty.NettyClient;
@@ -33,7 +32,6 @@
3332

3433
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
3534
import static java.net.HttpURLConnection.HTTP_OK;
36-
import static java.net.HttpURLConnection.HTTP_UNAVAILABLE;
3735
import static org.assertj.core.api.Assertions.assertThat;
3836
import static org.openqa.selenium.remote.http.Contents.asJson;
3937
import static org.openqa.selenium.remote.http.HttpMethod.GET;
@@ -47,7 +45,7 @@ public class RetryRequestTest {
4745
public void setUp() throws MalformedURLException {
4846
ClientConfig config = ClientConfig.defaultConfig()
4947
.baseUrl(URI.create("http://localhost:2345").toURL())
50-
.readTimeout(Duration.ofMillis(1000));
48+
.readTimeout(Duration.ofSeconds(1));
5149
client = new NettyClient.Factory().createClient(config);
5250
}
5351

@@ -77,7 +75,11 @@ public void shouldBeAbleToRetryARequestOnInternalServerError() {
7775
AtomicInteger count = new AtomicInteger(0);
7876
AppServer server = new NettyAppServer(req -> {
7977
count.incrementAndGet();
80-
return new HttpResponse().setStatus(500);
78+
if (count.get() <= 2) {
79+
return new HttpResponse().setStatus(500);
80+
} else {
81+
return new HttpResponse();
82+
}
8183
});
8284
server.start();
8385

@@ -87,7 +89,7 @@ public void shouldBeAbleToRetryARequestOnInternalServerError() {
8789
String.format(REQUEST_PATH, uri.getHost(), uri.getPort()));
8890
HttpResponse response = client.execute(request);
8991

90-
assertThat(response).extracting(HttpResponse::getStatus).isEqualTo(HTTP_INTERNAL_ERROR);
92+
assertThat(response).extracting(HttpResponse::getStatus).isEqualTo(HTTP_OK);
9193
assertThat(count.get()).isEqualTo(3);
9294

9395
server.stop();
@@ -121,9 +123,13 @@ public void shouldRetryRequestOnServerUnavailableError() {
121123
AtomicInteger count = new AtomicInteger(0);
122124
AppServer server = new NettyAppServer(req -> {
123125
count.incrementAndGet();
124-
return new HttpResponse()
125-
.setStatus(503)
126-
.setContent(asJson(ImmutableMap.of("error", "server down")));
126+
if (count.get() <= 2) {
127+
return new HttpResponse()
128+
.setStatus(503)
129+
.setContent(asJson(ImmutableMap.of("error", "server down")));
130+
} else {
131+
return new HttpResponse();
132+
}
127133
});
128134
server.start();
129135

@@ -132,8 +138,7 @@ public void shouldRetryRequestOnServerUnavailableError() {
132138
GET,
133139
String.format(REQUEST_PATH, uri.getHost(), uri.getPort()));
134140
HttpResponse response = client.execute(request);
135-
136-
assertThat(response).extracting(HttpResponse::getStatus).isEqualTo(HTTP_UNAVAILABLE);
141+
assertThat(response).extracting(HttpResponse::getStatus).isEqualTo(HTTP_OK);
137142
assertThat(count.get()).isEqualTo(3);
138143

139144
server.stop();
@@ -144,10 +149,12 @@ public void shouldBeAbleToRetryARequestOnTimeout() {
144149
AtomicInteger count = new AtomicInteger(0);
145150
AppServer server = new NettyAppServer(req -> {
146151
count.incrementAndGet();
147-
try {
148-
Thread.sleep(2000);
149-
} catch (InterruptedException e) {
150-
e.printStackTrace();
152+
if (count.get() <= 3) {
153+
try {
154+
Thread.sleep(2000);
155+
} catch (InterruptedException e) {
156+
e.printStackTrace();
157+
}
151158
}
152159
return new HttpResponse();
153160
});
@@ -158,13 +165,11 @@ public void shouldBeAbleToRetryARequestOnTimeout() {
158165
GET,
159166
String.format(REQUEST_PATH, uri.getHost(), uri.getPort()));
160167

161-
try {
162-
client.execute(request);
163-
} catch (TimeoutException e) {
164-
assertThat(count.get()).isEqualTo(4);
165-
} finally {
166-
server.stop();
167-
}
168+
HttpResponse response = client.execute(request);
169+
assertThat(response).extracting(HttpResponse::getStatus).isEqualTo(HTTP_OK);
170+
assertThat(count.get()).isEqualTo(4);
171+
172+
server.stop();
168173
}
169174

170175
@Test(expected = UncheckedIOException.class)

0 commit comments

Comments
 (0)