Skip to content

Commit

Permalink
Remove keep alive validation when current KA failure limit is exceeded (
Browse files Browse the repository at this point in the history
#40)

* Remove keepalive validation when current KA failure limit is exceeded

* Fix unit tests
  • Loading branch information
deepanshu42 authored Sep 1, 2022
1 parent 850a207 commit cec6975
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal class OptimalKeepAliveCalculator(
private fun calculateKeepAlive(): KeepAlive {
stateHandler.calculateNextKeepAlive()
return if (stateHandler.isCurrentKeepAliveFailureLimitExceeded()) {
onKeepAliveFailure(stateHandler.getCurrentKeepAlive())
handleKeepAliveFailure(stateHandler.getCurrentKeepAlive())
getUnderTrialKeepAlive()
} else {
stateHandler.updateProbeCountAndConvergenceTime()
Expand All @@ -77,16 +77,21 @@ internal class OptimalKeepAliveCalculator(
@Synchronized
override fun onKeepAliveFailure(keepAlive: KeepAlive) {
if (stateHandler.isValidKeepAlive(keepAlive)) {
stateHandler.updateKeepAliveFailureState(keepAlive)
if (stateHandler.isOptimalKeepAliveFound()) {
optimalKeepAliveObserver.onOptimalKeepAliveFound(
timeMinutes = stateHandler.getOptimalKeepAlive().keepAliveMinutes,
probeCount = stateHandler.getProbeCount(),
convergenceTime = stateHandler.getConvergenceTime()
)
}
stateHandler.updatePersistenceWithLatestState()
handleKeepAliveFailure(keepAlive)
}
}

@VisibleForTesting
internal fun handleKeepAliveFailure(keepAlive: KeepAlive) {
stateHandler.updateKeepAliveFailureState(keepAlive)
if (stateHandler.isOptimalKeepAliveFound()) {
optimalKeepAliveObserver.onOptimalKeepAliveFound(
timeMinutes = stateHandler.getOptimalKeepAlive().keepAliveMinutes,
probeCount = stateHandler.getProbeCount(),
convergenceTime = stateHandler.getConvergenceTime()
)
}
stateHandler.updatePersistenceWithLatestState()
}

@Synchronized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class OptimalKeepAliveCalculatorTest {
whenever(stateHandler.getCurrentKeepAlive()).thenReturn(keepAlive)

val optimalKeepAliveCalculatorSpy = spy(optimalKeepAliveCalculator)
doNothing().whenever(optimalKeepAliveCalculatorSpy).onKeepAliveFailure(keepAlive)
doNothing().whenever(optimalKeepAliveCalculatorSpy).handleKeepAliveFailure(keepAlive)

val underTrialKeepAlive = optimalKeepAliveCalculatorSpy.getUnderTrialKeepAlive()

Expand All @@ -120,7 +120,7 @@ class OptimalKeepAliveCalculatorTest {
verify(stateHandler).isCurrentKeepAliveFailureLimitExceeded()
verify(stateHandler).getCurrentKeepAlive()
verify(stateHandler).getOptimalKeepAlive()
verify(optimalKeepAliveCalculatorSpy).onKeepAliveFailure(keepAlive)
verify(optimalKeepAliveCalculatorSpy).handleKeepAliveFailure(keepAlive)
}

@Test
Expand Down

0 comments on commit cec6975

Please sign in to comment.