ably-cocoa icon indicating copy to clipboard operation
ably-cocoa copied to clipboard

Refactor incremental backoff and jitter with tests

Open sacOO7 opened this issue 1 year ago • 2 comments

Simplify unit tests for backoff and jitter since we already have a formula to generate lower and upper bounds.

Expression to calculate upper and lower bounds for generated values using getRetryTime

upper = min((retryCount + 2) / 3, 2) *initialTimeout lower = 0.8 * upper if x is a generated retryTimeout from getRetryTime, then

lower < x < upper

Backoff and jitter formula can be put in one file ARTBackoffRetryDelayCalculator.m same as https://github.com/ably/ably-java/blob/main/lib/src/main/java/io/ably/lib/util/ReconnectionStrategy.java So, other files BackoffCoefficients.swift, StaticJitterCoefficients.swift, ARTJitterCoefficientGenerator.m and ARTJitterCoefficientGenerator.h should be removed

Unit tests can be put in one file same as https://github.com/ably/ably-java/blob/main/lib/src/test/java/io/ably/lib/util/ReconnectionStrategyTest.java

So, other files DefaultJitterCoefficientGeneratorTests.swift and MockJitterCoefficientGenerator.swift can be removed

┆Issue is synchronized with this Jira Task by Unito

sacOO7 avatar Jan 30 '24 15:01 sacOO7

➤ Automation for Jira commented:

The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-4062

sync-by-unito[bot] avatar Jan 30 '24 15:01 sync-by-unito[bot]

I think that writing tests is a pretty subjective thing and there frequently isn’t really a "right" way to do it — I was satisfied with the way I did these tests, but if someone wants to change them feel free 🙂

lawrence-forooghian avatar Apr 22 '24 18:04 lawrence-forooghian