Skip to content

Commit

Permalink
also test the case when backoff is triggered from CONNECTED state
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Guggemos <dominik.guggemos@bosch.io>
  • Loading branch information
dguggemos committed Sep 8, 2021
1 parent 05df83b commit 9a08983
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,16 @@ public void reconnectsInConnectingStateIfFailureResponseReceived() {
}

@Test
public void reconnectsInConnectingStateAfterBackoffWhenMultipleFailuresReceived() {
public void reconnectsInConnectingStateAfterBackoffWhenMultipleFailuresAreReceived() {
reconnectsAfterBackoffWhenMultipleFailuresReceived(false);
}

@Test
public void reconnectsFromConnectedStateAfterBackoffWhenMultipleFailuresAreReceived() {
reconnectsAfterBackoffWhenMultipleFailuresReceived(true);
}

private void reconnectsAfterBackoffWhenMultipleFailuresReceived(final boolean initialConnectionSucceeds) {
new TestKit(actorSystem) {{
final ConnectionId randomConnectionId = TestConstants.createRandomConnectionId();
final Connection connection =
Expand All @@ -143,6 +152,16 @@ public void reconnectsInConnectingStateAfterBackoffWhenMultipleFailuresReceived(
whenOpeningConnection(dummyClientActor, OpenConnection.of(randomConnectionId, DittoHeaders.empty()),
getRef());
thenExpectConnectClientCalled();

if (initialConnectionSucceeds) {
// simulate initial connection succeeds i.e. state is CONNECTED when first failure occurs
andConnectionSuccessful(dummyClientActor, getRef());
expectMsg(CONNECTED_STATUS);
andConnectionNotSuccessful(dummyClientActor);
thenExpectConnectClientCalledAfterTimeout(
connectivityConfig.getClientConfig().getConnectingMinTimeout());
}

final int nrOfBackoffs = 4;
final long start = System.currentTimeMillis();
for (int i = 0; i < nrOfBackoffs; i++) {
Expand Down

0 comments on commit 9a08983

Please sign in to comment.