From d0be180a690602bbec831eead79d63b7f1dbd3c7 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Wed, 10 Dec 2025 14:22:42 +0100 Subject: [PATCH] =?UTF-8?q?Make=20@=E2=80=8BRetryable=20and=20RetryTemplat?= =?UTF-8?q?e=20timeout=20tests=20more=20robust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See gh-35963 --- .../ReactiveRetryInterceptorTests.java | 14 +++++----- .../resilience/RetryInterceptorTests.java | 10 +++---- .../core/retry/RetryTemplateTests.java | 26 +++++++++---------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/spring-context/src/test/java/org/springframework/resilience/ReactiveRetryInterceptorTests.java b/spring-context/src/test/java/org/springframework/resilience/ReactiveRetryInterceptorTests.java index 065c22c2081..152c74156bb 100644 --- a/spring-context/src/test/java/org/springframework/resilience/ReactiveRetryInterceptorTests.java +++ b/spring-context/src/test/java/org/springframework/resilience/ReactiveRetryInterceptorTests.java @@ -351,7 +351,7 @@ class ReactiveRetryInterceptorTests { .satisfies(isReactiveException()) .havingCause() .isInstanceOf(TimeoutException.class) - .withMessageContaining("within 5ms"); + .withMessageContaining("within 20ms"); // 1 initial attempt + 0 retries assertThat(target.counter).hasValue(1); } @@ -363,7 +363,7 @@ class ReactiveRetryInterceptorTests { .satisfies(isReactiveException()) .havingCause() .isInstanceOf(TimeoutException.class) - .withMessageContaining("within 5ms"); + .withMessageContaining("within 20ms"); // 1 initial attempt + 0 retries assertThat(target.counter).hasValue(1); } @@ -464,16 +464,16 @@ class ReactiveRetryInterceptorTests { }); } - @Retryable(timeout = 5, delay = 0) + @Retryable(timeout = 20, delay = 0) public Mono retryOperationWithTimeoutExceededAfterInitialFailure() { return Mono.fromCallable(() -> { counter.incrementAndGet(); - Thread.sleep(20); + Thread.sleep(100); throw new IOException(counter.toString()); }); } - @Retryable(timeout = 5, delay = 10) + @Retryable(timeout = 20, delay = 100) // Delay > Timeout public Mono retryOperationWithTimeoutExceededAfterFirstDelayButBeforeFirstRetry() { return Mono.fromCallable(() -> { counter.incrementAndGet(); @@ -486,7 +486,7 @@ class ReactiveRetryInterceptorTests { return Mono.fromCallable(() -> { counter.incrementAndGet(); if (counter.get() == 2) { - Thread.sleep(50); + Thread.sleep(100); } throw new IOException(counter.toString()); }); @@ -497,7 +497,7 @@ class ReactiveRetryInterceptorTests { return Mono.fromCallable(() -> { counter.incrementAndGet(); if (counter.get() == 3) { - Thread.sleep(50); + Thread.sleep(100); } throw new IOException(counter.toString()); }); diff --git a/spring-context/src/test/java/org/springframework/resilience/RetryInterceptorTests.java b/spring-context/src/test/java/org/springframework/resilience/RetryInterceptorTests.java index 8da69719e1c..85a146b5254 100644 --- a/spring-context/src/test/java/org/springframework/resilience/RetryInterceptorTests.java +++ b/spring-context/src/test/java/org/springframework/resilience/RetryInterceptorTests.java @@ -426,14 +426,14 @@ class RetryInterceptorTests { throw new IOException(Integer.toString(counter)); } - @Retryable(timeout = 5, delay = 10) + @Retryable(timeout = 20, delay = 0) public void retryOperationWithTimeoutExceededAfterInitialFailure() throws Exception { counter++; - Thread.sleep(10); + Thread.sleep(100); throw new IOException(Integer.toString(counter)); } - @Retryable(timeout = 5, delay = 10) + @Retryable(timeout = 20, delay = 100) // Delay > Timeout public void retryOperationWithTimeoutExceededAfterFirstDelayButBeforeFirstRetry() throws IOException { counter++; throw new IOException(Integer.toString(counter)); @@ -443,7 +443,7 @@ class RetryInterceptorTests { public void retryOperationWithTimeoutExceededAfterFirstRetry() throws Exception { counter++; if (counter == 2) { - Thread.sleep(50); + Thread.sleep(100); } throw new IOException(Integer.toString(counter)); } @@ -452,7 +452,7 @@ class RetryInterceptorTests { public void retryOperationWithTimeoutExceededAfterSecondRetry() throws Exception { counter++; if (counter == 3) { - Thread.sleep(50); + Thread.sleep(100); } throw new IOException(Integer.toString(counter)); } diff --git a/spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java b/spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java index f5af910958e..94409088acf 100644 --- a/spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java +++ b/spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java @@ -413,14 +413,14 @@ class RetryTemplateTests { @Test void retryWithImmediateSuccessAndTimeoutExceeded() throws Exception { - RetryPolicy retryPolicy = RetryPolicy.builder().timeout(Duration.ofMillis(5)).build(); + RetryPolicy retryPolicy = RetryPolicy.builder().timeout(Duration.ofMillis(10)).build(); RetryTemplate retryTemplate = new RetryTemplate(retryPolicy); retryTemplate.setRetryListener(retryListener); AtomicInteger invocationCount = new AtomicInteger(); Retryable retryable = () -> { invocationCount.incrementAndGet(); - Thread.sleep(10); + Thread.sleep(100); return "always succeeds"; }; @@ -435,7 +435,7 @@ class RetryTemplateTests { @Test void retryWithInitialFailureAndZeroRetriesRetryPolicyAndTimeoutExceeded() { RetryPolicy retryPolicy = RetryPolicy.builder() - .timeout(Duration.ofMillis(5)) + .timeout(Duration.ofMillis(10)) .predicate(throwable -> false) // Zero retries .build(); RetryTemplate retryTemplate = new RetryTemplate(retryPolicy); @@ -443,7 +443,7 @@ class RetryTemplateTests { Exception exception = new RuntimeException("Boom!"); Retryable retryable = () -> { - Thread.sleep(10); + Thread.sleep(100); throw exception; }; @@ -461,7 +461,7 @@ class RetryTemplateTests { @Test void retryWithTimeoutExceededAfterInitialFailure() throws Exception { RetryPolicy retryPolicy = RetryPolicy.builder() - .timeout(Duration.ofMillis(5)) + .timeout(Duration.ofMillis(10)) .delay(Duration.ZERO) .build(); RetryTemplate retryTemplate = new RetryTemplate(retryPolicy); @@ -469,14 +469,14 @@ class RetryTemplateTests { AtomicInteger invocationCount = new AtomicInteger(); Retryable retryable = () -> { - Thread.sleep(10); + Thread.sleep(100); throw new CustomException("Boom " + invocationCount.incrementAndGet()); }; assertThat(invocationCount).hasValue(0); assertThatExceptionOfType(RetryException.class) .isThrownBy(() -> retryTemplate.execute(retryable)) - .withMessageMatching("Retry policy for operation '.+?' exceeded timeout \\(5ms\\); aborting execution") + .withMessageMatching("Retry policy for operation '.+?' exceeded timeout \\(10ms\\); aborting execution") .withCause(new CustomException("Boom 1")) .satisfies(throwable -> inOrder.verify(retryListener).onRetryPolicyTimeout( eq(retryPolicy), eq(retryable), eq(throwable))); @@ -488,8 +488,8 @@ class RetryTemplateTests { @Test void retryWithTimeoutExceededAfterFirstDelayButBeforeFirstRetry() throws Exception { RetryPolicy retryPolicy = RetryPolicy.builder() - .timeout(Duration.ofMillis(5)) - .delay(Duration.ofMillis(10)) // Delay > Timeout + .timeout(Duration.ofMillis(20)) + .delay(Duration.ofMillis(100)) // Delay > Timeout .build(); RetryTemplate retryTemplate = new RetryTemplate(retryPolicy); retryTemplate.setRetryListener(retryListener); @@ -503,8 +503,8 @@ class RetryTemplateTests { assertThatExceptionOfType(RetryException.class) .isThrownBy(() -> retryTemplate.execute(retryable)) .withMessageMatching(""" - Retry policy for operation '.+?' would exceed timeout \\(5ms\\) \ - due to pending sleep time \\(10ms\\); preemptively aborting execution\ + Retry policy for operation '.+?' would exceed timeout \\(20ms\\) \ + due to pending sleep time \\(100ms\\); preemptively aborting execution\ """) .withCause(new CustomException("Boom 1")) .satisfies(throwable -> inOrder.verify(retryListener).onRetryPolicyTimeout( @@ -527,7 +527,7 @@ class RetryTemplateTests { Retryable retryable = () -> { int currentInvocation = invocationCount.incrementAndGet(); if (currentInvocation == 2) { - Thread.sleep(50); + Thread.sleep(100); } throw new CustomException("Boom " + currentInvocation); }; @@ -562,7 +562,7 @@ class RetryTemplateTests { Retryable retryable = () -> { int currentInvocation = invocationCount.incrementAndGet(); if (currentInvocation == 3) { - Thread.sleep(50); + Thread.sleep(100); } throw new CustomException("Boom " + currentInvocation); };