From 5d32f6719a0ab2703baa7ca467448445cda2dbb2 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Fri, 18 Sep 2026 14:05:38 +0200 Subject: [PATCH] Fix flaky test in RetryTemplateTests `RetryTemplateTests` can, under load, break the build because of a flaky test: "retryableWithTimeoutExceededAfterSecondRetry". This usually happens when many cores are busy and the timeout check runs before each retry attempt. This commit extends the timeout to avoid such cases and failures. --- .../org/springframework/core/retry/RetryTemplateTests.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 a58e366c503..0b37eb2fb95 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 @@ -780,7 +780,7 @@ class RetryTemplateTests { @Test void retryableWithTimeoutExceededAfterSecondRetry() { RetryPolicy retryPolicy = RetryPolicy.builder() - .timeout(Duration.ofMillis(20)) + .timeout(Duration.ofMillis(200)) .delay(Duration.ZERO) .build(); RetryTemplate retryTemplate = new RetryTemplate(retryPolicy); @@ -790,7 +790,7 @@ class RetryTemplateTests { Retryable retryable = () -> { int currentInvocation = invocationCount.incrementAndGet(); if (currentInvocation == 3) { - Thread.sleep(100); + Thread.sleep(500); } throw new CustomException("Boom " + currentInvocation); }; @@ -798,7 +798,7 @@ class RetryTemplateTests { assertThat(invocationCount).hasValue(0); assertThatExceptionOfType(RetryException.class) .isThrownBy(() -> retryTemplate.execute(retryable)) - .withMessageMatching("Retry policy for operation '.+?' exceeded timeout \\(20ms\\); aborting execution") + .withMessageMatching("Retry policy for operation '.+?' exceeded timeout \\(200ms\\); aborting execution") .withCause(new CustomException("Boom 3")) .satisfies(throwable -> { var counter = new AtomicInteger(1);