@@ -210,7 +210,7 @@ public boolean shouldRetry(Throwable previousThrowable, Object previousResponse)
210210 Arrays .stream (suppressed ).map (Throwable ::getMessage ).collect (Collectors .toList ());
211211 assertThat (suppressedMessages )
212212 .containsExactly (
213- "Unretryable error (attempts: 1, maxAttempts: 6, elapsed: PT9.002S , nextBackoff: PT3S)" );
213+ "Unretryable error (attempts: 1, maxAttempts: 6, elapsed: PT0S , nextBackoff: PT3S)" );
214214 });
215215 }
216216
@@ -381,6 +381,35 @@ public boolean shouldRetry(Throwable previousThrowable, Object previousResponse)
381381 assertThat (retryContextSplits .size ()).isEqualTo (retryHelperSplits .size ());
382382 }
383383
384+ @ Test
385+ public void resetAlsoResetsBackoffState () throws Exception {
386+ Throwable t1 = apiException (Code .INTERNAL , "{err1}" );
387+ Throwable t2 = apiException (Code .INTERNAL , "{err2}" );
388+ RetryContext ctx =
389+ RetryContext .of (
390+ scheduledExecutorService , maxAttempts (1 ), Retrying .alwaysRetry (), Jitterer .noJitter ());
391+
392+ AtomicReference <Throwable > err1 = new AtomicReference <>();
393+ AtomicReference <Throwable > err2 = new AtomicReference <>();
394+ ctx .recordError (t1 , failOnSuccess (), err1 ::set );
395+ ctx .reset ();
396+ ctx .recordError (t2 , failOnSuccess (), err2 ::set );
397+
398+ assertAll (
399+ () -> {
400+ String messages = TestUtils .messagesToText (err1 .get ());
401+ assertThat (messages )
402+ .contains (
403+ "Operation failed to complete within attempt budget (attempts: 1, maxAttempts: 1, elapsed: PT0S, nextBackoff: PT3S)" );
404+ },
405+ () -> {
406+ String messages = TestUtils .messagesToText (err2 .get ());
407+ assertThat (messages )
408+ .contains (
409+ "Operation failed to complete within attempt budget (attempts: 1, maxAttempts: 1, elapsed: PT0S, nextBackoff: PT3S)" );
410+ });
411+ }
412+
384413 private static ApiException apiException (Code code , String message ) {
385414 return ApiExceptionFactory .createException (message , null , GrpcStatusCode .of (code ), false );
386415 }
0 commit comments