@Test
void collectsSuppressedErrorsAsync()
{

    String result = "The Result";
    long maxRetryTime = 20;
    int initialDelay = 15;
    int multiplier = 2;
    Clock clock = mock( Clock.class );
    when( clock.millis() ).thenReturn( 0L ).thenReturn( 10L ).thenReturn( 15L ).thenReturn( 25L );
    ExponentialBackoffRetryLogic retryLogic = newRetryLogic( maxRetryTime, initialDelay, multiplier, 0, clock );
    Supplier<CompletionStage<Object>> workMock = newWorkMock();
    SessionExpiredException error1 = sessionExpired();
    SessionExpiredException error2 = sessionExpired();
    ServiceUnavailableException error3 = serviceUnavailable();
    TransientException error4 = transientException();
    when( workMock.get() ).thenReturn( failedFuture( error1 ) )
            .thenReturn( failedFuture( error2 ) )
            .thenReturn( failedFuture( error3 ) )
            .thenReturn( failedFuture( error4 ) )
            .thenReturn( completedFuture( result ) );
    Exception e = assertThrows( Exception.class, () -> await( retryLogic.retryAsync( workMock ) ) );
    assertEquals( error4, e );
    Throwable[] suppressed = e.getSuppressed();
    assertEquals( 3, suppressed.length );
    assertEquals( error1, suppressed[0] );
    assertEquals( error2, suppressed[1] );
    assertEquals( error3, suppressed[2] );
    verify( workMock, times( 4 ) ).get();
    List<Long> scheduleDelays = eventExecutor.scheduleDelays();
    assertEquals( 3, scheduleDelays.size() );
    assertEquals( initialDelay, scheduleDelays.get( 0 ).intValue() );
    assertEquals( initialDelay * multiplier, scheduleDelays.get( 1 ).intValue() );
    assertEquals( initialDelay * multiplier * multiplier, scheduleDelays.get( 2 ).intValue() );
}