Skip to content

Commit

Permalink
Add test for Retry-After header exceeding maximum SSE reconnect wait …
Browse files Browse the repository at this point in the history
…time

Also-by: Bert Plonus <bert.plonus@miele.com>
Also-by: Martin Lepsy <martin.lepsy@miele.com>
Also-by: Benjamin Bolte <benjamin.bolte@itemis.de>
Signed-off-by: Björn Lange <bjoern.lange@itemis.de>
  • Loading branch information
Björn Lange committed Feb 3, 2021
1 parent 12afaf8 commit ff76f65
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private BackoffStrategy mockBackoffStrategy() {
BackoffStrategy backoffStrategy = mock(BackoffStrategy.class);
when(backoffStrategy.getSecondsUntilRetry(anyInt())).thenReturn(10L);
when(backoffStrategy.getMinimumSecondsUntilRetry()).thenReturn(5L);
when(backoffStrategy.getMaximumSecondsUntilRetry()).thenReturn(Long.MAX_VALUE);
when(backoffStrategy.getMaximumSecondsUntilRetry()).thenReturn(3600L);
return backoffStrategy;
}

Expand Down Expand Up @@ -401,6 +401,29 @@ public void whenTheSseRequestCompletesWithATooManyRequestsResponseWithRetryAfter
verify(getMockedSseListener()).onConnectionError(ConnectionError.TOO_MANY_RERQUESTS, 0);
}

@Test
public void whenTheSseRequestCompletesWithATooManyRequestsResponseWithRetryAfterHeaderWithTooHighValueThenAReconnectIsScheduledWithTheMaximumWaitTime()
throws Exception {
// given:
setUpRunningConnection();

Response response = mock(Response.class);
when(response.getStatus()).thenReturn(429);
HttpFields httpFields = new HttpFields();
httpFields.add("Retry-After", "3601");
when(response.getHeaders()).thenReturn(httpFields);

Result result = mock(Result.class);
when(result.getResponse()).thenReturn(response);

// when:
getRegisteredCompleteListener().onComplete(result);

// then:
verify(getMockedScheduler()).schedule(ArgumentMatchers.<Runnable> any(), eq(3600L), eq(TimeUnit.SECONDS));
verify(getMockedSseListener()).onConnectionError(ConnectionError.TOO_MANY_RERQUESTS, 0);
}

@Test
public void whenTheSseRequestCompletesWithAnInternalServerErrorResponseThenAReconnectIsScheduledAndTheListenersAreNotified()
throws Exception {
Expand Down

0 comments on commit ff76f65

Please sign in to comment.