From 4770e62ef7ff9ec6b7e9b15775ee5b8e55bb16c0 Mon Sep 17 00:00:00 2001 From: courtneyeh Date: Mon, 6 May 2024 16:01:48 +1000 Subject: [PATCH] Move retries to constant --- .../teku/validator/client/loader/ExternalUrlKeyReader.java | 3 ++- .../validator/client/loader/ExternalUrlKeyReaderTest.java | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/validator/client/src/main/java/tech/pegasys/teku/validator/client/loader/ExternalUrlKeyReader.java b/validator/client/src/main/java/tech/pegasys/teku/validator/client/loader/ExternalUrlKeyReader.java index 08f1ad010d9..7083bf96b3b 100644 --- a/validator/client/src/main/java/tech/pegasys/teku/validator/client/loader/ExternalUrlKeyReader.java +++ b/validator/client/src/main/java/tech/pegasys/teku/validator/client/loader/ExternalUrlKeyReader.java @@ -31,6 +31,7 @@ public class ExternalUrlKeyReader { private static final Duration FIXED_DELAY = Duration.ofSeconds(5); + private static final int MAX_RETRIES = 59; private final String url; private final ObjectMapper mapper; @@ -76,7 +77,7 @@ SafeFuture retry() { return readUrl(); }, FIXED_DELAY, - 59) + MAX_RETRIES) .exceptionallyCompose( ex -> SafeFuture.failedFuture( diff --git a/validator/client/src/test/java/tech/pegasys/teku/validator/client/loader/ExternalUrlKeyReaderTest.java b/validator/client/src/test/java/tech/pegasys/teku/validator/client/loader/ExternalUrlKeyReaderTest.java index 01f931f8b05..39d747f05a0 100644 --- a/validator/client/src/test/java/tech/pegasys/teku/validator/client/loader/ExternalUrlKeyReaderTest.java +++ b/validator/client/src/test/java/tech/pegasys/teku/validator/client/loader/ExternalUrlKeyReaderTest.java @@ -43,6 +43,7 @@ class ExternalUrlKeyReaderTest { private static final Duration DELAY = Duration.ofSeconds(5); + private static final int MAX_RETRIES = 59; private static final String VALID_URL = "http://test:0000/api/v1/eth2/publicKeys"; private final ObjectMapper mapper = mock(ObjectMapper.class); @@ -125,7 +126,7 @@ void readKeysWithRetry_unreachableUrlRetryUntilMaxRetries() throws IOException { final ExternalUrlKeyReader reader = new ExternalUrlKeyReader(VALID_URL, mapper, asyncRunner); final SafeFuture keys = reader.retry(); - for (int i = 0; i < 59; i++) { + for (int i = 0; i < MAX_RETRIES; i++) { assertThat(keys).isNotCompleted(); timeProvider.advanceTimeBy(DELAY); asyncRunner.executeQueuedActions(); @@ -135,6 +136,6 @@ void readKeysWithRetry_unreachableUrlRetryUntilMaxRetries() throws IOException { .isInstanceOf(CompletionException.class) .hasCauseInstanceOf(InvalidConfigurationException.class) .hasRootCause(exception); - verify(mapper, times(60)).readValue(any(URL.class), eq(String[].class)); + verify(mapper, times(MAX_RETRIES + 1)).readValue(any(URL.class), eq(String[].class)); } }