ably-cocoa
ably-cocoa copied to clipboard
Refactor incremental backoff and jitter with tests
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
➤ Automation for Jira commented:
The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-4062
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 🙂