Browse Source

Make RetryTemplate timeout tests more robust

See gh-35963
pull/35990/head
Sam Brannen 1 week ago
parent
commit
38cf4ab3fc
  1. 12
      spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java

12
spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java

@ -517,7 +517,7 @@ class RetryTemplateTests {
@Test @Test
void retryWithTimeoutExceededAfterFirstRetry() throws Exception { void retryWithTimeoutExceededAfterFirstRetry() throws Exception {
RetryPolicy retryPolicy = RetryPolicy.builder() RetryPolicy retryPolicy = RetryPolicy.builder()
.timeout(Duration.ofMillis(5)) .timeout(Duration.ofMillis(20))
.delay(Duration.ZERO) .delay(Duration.ZERO)
.build(); .build();
RetryTemplate retryTemplate = new RetryTemplate(retryPolicy); RetryTemplate retryTemplate = new RetryTemplate(retryPolicy);
@ -527,7 +527,7 @@ class RetryTemplateTests {
Retryable<String> retryable = () -> { Retryable<String> retryable = () -> {
int currentInvocation = invocationCount.incrementAndGet(); int currentInvocation = invocationCount.incrementAndGet();
if (currentInvocation == 2) { if (currentInvocation == 2) {
Thread.sleep(10); Thread.sleep(50);
} }
throw new CustomException("Boom " + currentInvocation); throw new CustomException("Boom " + currentInvocation);
}; };
@ -535,7 +535,7 @@ class RetryTemplateTests {
assertThat(invocationCount).hasValue(0); assertThat(invocationCount).hasValue(0);
assertThatExceptionOfType(RetryException.class) assertThatExceptionOfType(RetryException.class)
.isThrownBy(() -> retryTemplate.execute(retryable)) .isThrownBy(() -> retryTemplate.execute(retryable))
.withMessageMatching("Retry policy for operation '.+?' exceeded timeout \\(5 ms\\); aborting execution") .withMessageMatching("Retry policy for operation '.+?' exceeded timeout \\(20 ms\\); aborting execution")
.withCause(new CustomException("Boom 2")) .withCause(new CustomException("Boom 2"))
.satisfies(throwable -> { .satisfies(throwable -> {
inOrder.verify(retryListener).beforeRetry(retryPolicy, retryable); inOrder.verify(retryListener).beforeRetry(retryPolicy, retryable);
@ -552,7 +552,7 @@ class RetryTemplateTests {
@Test @Test
void retryWithTimeoutExceededAfterSecondRetry() throws Exception { void retryWithTimeoutExceededAfterSecondRetry() throws Exception {
RetryPolicy retryPolicy = RetryPolicy.builder() RetryPolicy retryPolicy = RetryPolicy.builder()
.timeout(Duration.ofMillis(5)) .timeout(Duration.ofMillis(20))
.delay(Duration.ZERO) .delay(Duration.ZERO)
.build(); .build();
RetryTemplate retryTemplate = new RetryTemplate(retryPolicy); RetryTemplate retryTemplate = new RetryTemplate(retryPolicy);
@ -562,7 +562,7 @@ class RetryTemplateTests {
Retryable<String> retryable = () -> { Retryable<String> retryable = () -> {
int currentInvocation = invocationCount.incrementAndGet(); int currentInvocation = invocationCount.incrementAndGet();
if (currentInvocation == 3) { if (currentInvocation == 3) {
Thread.sleep(10); Thread.sleep(50);
} }
throw new CustomException("Boom " + currentInvocation); throw new CustomException("Boom " + currentInvocation);
}; };
@ -570,7 +570,7 @@ class RetryTemplateTests {
assertThat(invocationCount).hasValue(0); assertThat(invocationCount).hasValue(0);
assertThatExceptionOfType(RetryException.class) assertThatExceptionOfType(RetryException.class)
.isThrownBy(() -> retryTemplate.execute(retryable)) .isThrownBy(() -> retryTemplate.execute(retryable))
.withMessageMatching("Retry policy for operation '.+?' exceeded timeout \\(5 ms\\); aborting execution") .withMessageMatching("Retry policy for operation '.+?' exceeded timeout \\(20 ms\\); aborting execution")
.withCause(new CustomException("Boom 3")) .withCause(new CustomException("Boom 3"))
.satisfies(throwable -> { .satisfies(throwable -> {
var counter = new AtomicInteger(1); var counter = new AtomicInteger(1);

Loading…
Cancel
Save