Skip to content

Commit

Permalink
chore: add more automated retry tests (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
rishtigupta authored Feb 12, 2025
1 parent 12200f9 commit 4d878cb
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,40 @@ void testNonRetryEligibleApi_shouldMakeLessThanMaxAttempts_WhenTemporaryNetworkO
testRetryMetricsMiddlewareArgs,
(cacheClient, cacheName) -> {
assertThat(cacheClient.get(cacheName, "key"))
.succeedsWithin(FIVE_SECONDS)
.succeedsWithin(Duration.ofSeconds(10))
.isInstanceOf(GetResponse.Miss.class);

assertThat(testRetryMetricsCollector.getTotalRetryCount(cacheName, MomentoRpcMethod.GET))
.isEqualTo(0);
});
}

@Test
void testRetryEligibleApi_shouldMakeMaxRetries_WhenDelayMillisIsLessThanMaxDelayMillis()
throws Exception {
long maxDelayMillis = 5000L;

FixedDelayRetryStrategy retryStrategy =
new FixedDelayRetryStrategy(maxAttempts, delayMillis, maxDelayMillis);

TestRetryMetricsMiddlewareArgs testRetryMetricsMiddlewareArgs =
new TestRetryMetricsMiddlewareArgs.Builder(
logger, testRetryMetricsCollector, UUID.randomUUID().toString())
.returnError(MomentoErrorCode.SERVER_UNAVAILABLE.name())
.errorRpcList(Collections.singletonList(MomentoRpcMethod.GET.getRequestName()))
.build();

withCacheAndCacheClient(
config -> config.withRetryStrategy(retryStrategy).withTimeout(CLIENT_TIMEOUT_MILLIS),
testRetryMetricsMiddlewareArgs,
(cacheClient, cacheName) -> {
assertThat(cacheClient.get(cacheName, "key"))
.succeedsWithin(Duration.ofSeconds(10))
.extracting(GetResponse::getClass)
.isEqualTo(GetResponse.Error.class);

assertThat(testRetryMetricsCollector.getTotalRetryCount(cacheName, MomentoRpcMethod.GET))
.isEqualTo(4);
});
}
}

0 comments on commit 4d878cb

Please sign in to comment.