Improve error message for preemptive timeout in RetryTemplate

The error message in such cases now indicates that the retry process
is being aborted preemptively due to pending sleep time.

For example:

  Retry policy for operation 'myMethod' would exceed timeout (5 ms) due
  to pending sleep time (10 ms); preemptively aborting execution

See gh-35963
This commit is contained in:
Sam Brannen
2025-12-09 16:46:44 +01:00
parent 2643c6212f
commit 61201db704
2 changed files with 10 additions and 3 deletions
@@ -502,7 +502,10 @@ class RetryTemplateTests {
assertThat(invocationCount).hasValue(0);
assertThatExceptionOfType(RetryException.class)
.isThrownBy(() -> retryTemplate.execute(retryable))
.withMessageMatching("Retry policy for operation '.+?' exceeded timeout \\(5 ms\\); aborting execution")
.withMessageMatching("""
Retry policy for operation '.+?' would exceed timeout \\(5 ms\\) \
due to pending sleep time \\(10 ms\\); preemptively aborting execution\
""")
.withCause(new CustomException("Boom 1"))
.satisfies(throwable -> inOrder.verify(retryListener).onRetryPolicyTimeout(
eq(retryPolicy), eq(retryable), eq(throwable)));