Skip to content

Commit 4770e62

Browse files
committed
Move retries to constant
1 parent 0cd7f64 commit 4770e62

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

validator/client/src/main/java/tech/pegasys/teku/validator/client/loader/ExternalUrlKeyReader.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
public class ExternalUrlKeyReader {
3333
private static final Duration FIXED_DELAY = Duration.ofSeconds(5);
34+
private static final int MAX_RETRIES = 59;
3435

3536
private final String url;
3637
private final ObjectMapper mapper;
@@ -76,7 +77,7 @@ SafeFuture<String[]> retry() {
7677
return readUrl();
7778
},
7879
FIXED_DELAY,
79-
59)
80+
MAX_RETRIES)
8081
.exceptionallyCompose(
8182
ex ->
8283
SafeFuture.failedFuture(

validator/client/src/test/java/tech/pegasys/teku/validator/client/loader/ExternalUrlKeyReaderTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
class ExternalUrlKeyReaderTest {
4545
private static final Duration DELAY = Duration.ofSeconds(5);
46+
private static final int MAX_RETRIES = 59;
4647
private static final String VALID_URL = "http://test:0000/api/v1/eth2/publicKeys";
4748

4849
private final ObjectMapper mapper = mock(ObjectMapper.class);
@@ -125,7 +126,7 @@ void readKeysWithRetry_unreachableUrlRetryUntilMaxRetries() throws IOException {
125126
final ExternalUrlKeyReader reader = new ExternalUrlKeyReader(VALID_URL, mapper, asyncRunner);
126127

127128
final SafeFuture<String[]> keys = reader.retry();
128-
for (int i = 0; i < 59; i++) {
129+
for (int i = 0; i < MAX_RETRIES; i++) {
129130
assertThat(keys).isNotCompleted();
130131
timeProvider.advanceTimeBy(DELAY);
131132
asyncRunner.executeQueuedActions();
@@ -135,6 +136,6 @@ void readKeysWithRetry_unreachableUrlRetryUntilMaxRetries() throws IOException {
135136
.isInstanceOf(CompletionException.class)
136137
.hasCauseInstanceOf(InvalidConfigurationException.class)
137138
.hasRootCause(exception);
138-
verify(mapper, times(60)).readValue(any(URL.class), eq(String[].class));
139+
verify(mapper, times(MAX_RETRIES + 1)).readValue(any(URL.class), eq(String[].class));
139140
}
140141
}

0 commit comments

Comments
 (0)