Skip to content

Commit c626cbf

Browse files
committed
default min delay is 100ms, not 500ms
1 parent 3903c32 commit c626cbf

3 files changed

Lines changed: 25 additions & 25 deletions

File tree

src/main/java/dev/openfga/sdk/util/ExponentialBackoff.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
* Utility class for calculating exponential backoff delays with jitter.
2020
*
2121
* Implements the retry strategy specified in GitHub issue #155:
22-
* - Base delay: 2^retryCount * 500ms
22+
* - Base delay: 2^retryCount * 100ms
2323
* - Jitter: Random value between base and 2 * base
24-
* - Maximum delay: 120 seconds (capped after 8th retry)
24+
* - Maximum delay: 120 seconds (capped after 10th retry)
2525
*/
2626
public class ExponentialBackoff {
2727

28-
private static final int BASE_DELAY_MS = 500;
28+
private static final int BASE_DELAY_MS = 100;
2929
private static final int MAX_DELAY_SECONDS = 120;
3030
private static final Random RANDOM = new Random();
3131

src/test/java/dev/openfga/sdk/util/ExponentialBackoffTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ void calculateDelay_withRetryCountZero_shouldReturnBaseDelay() {
3030
Duration result = ExponentialBackoff.calculateDelay(retryCount, fixedRandom);
3131

3232
// Then
33-
// For retry count 0: 2^0 * 500ms = 500ms base
34-
// With jitter: between 500ms and 1000ms
35-
assertThat(result.toMillis()).isBetween(500L, 1000L);
33+
// For retry count 0: 2^0 * 100ms = 100ms base
34+
// With jitter: between 100ms and 200ms
35+
assertThat(result.toMillis()).isBetween(100L, 200L);
3636
}
3737

3838
@Test
@@ -45,9 +45,9 @@ void calculateDelay_withRetryCountOne_shouldReturnDoubledDelay() {
4545
Duration result = ExponentialBackoff.calculateDelay(retryCount, fixedRandom);
4646

4747
// Then
48-
// For retry count 1: 2^1 * 500ms = 1000ms base
49-
// With jitter: between 1000ms and 2000ms
50-
assertThat(result.toMillis()).isBetween(1000L, 2000L);
48+
// For retry count 1: 2^1 * 100ms = 200ms base
49+
// With jitter: between 200ms and 400ms
50+
assertThat(result.toMillis()).isBetween(200L, 400L);
5151
}
5252

5353
@Test
@@ -60,15 +60,15 @@ void calculateDelay_withRetryCountTwo_shouldReturnQuadrupledDelay() {
6060
Duration result = ExponentialBackoff.calculateDelay(retryCount, fixedRandom);
6161

6262
// Then
63-
// For retry count 2: 2^2 * 500ms = 2000ms base
64-
// With jitter: between 2000ms and 4000ms
65-
assertThat(result.toMillis()).isBetween(2000L, 4000L);
63+
// For retry count 2: 2^2 * 100ms = 400ms base
64+
// With jitter: between 400ms and 800ms
65+
assertThat(result.toMillis()).isBetween(400L, 800L);
6666
}
6767

6868
@Test
6969
void calculateDelay_withHighRetryCount_shouldCapAtMaximum() {
7070
// Given
71-
int retryCount = 10; // This would normally result in 2^10 * 500ms = 512000ms
71+
int retryCount = 10; // This would normally result in 2^10 * 100ms = 102400ms
7272
Random fixedRandom = new Random(42); // Fixed seed for deterministic testing
7373

7474
// When
@@ -100,9 +100,9 @@ void calculateDelay_withoutRandomParameter_shouldReturnValidRange() {
100100
Duration result = ExponentialBackoff.calculateDelay(retryCount);
101101

102102
// Then
103-
// For retry count 1: 2^1 * 500ms = 1000ms base
104-
// With jitter: between 1000ms and 2000ms
105-
assertThat(result.toMillis()).isBetween(1000L, 2000L);
103+
// For retry count 1: 2^1 * 100ms = 200ms base
104+
// With jitter: between 200ms and 400ms
105+
assertThat(result.toMillis()).isBetween(200L, 400L);
106106
}
107107

108108
@Test
@@ -116,9 +116,9 @@ void calculateDelay_shouldProduceVariousResults() {
116116
Duration result3 = ExponentialBackoff.calculateDelay(retryCount);
117117

118118
// Then - all should be in valid range but likely different
119-
assertThat(result1.toMillis()).isBetween(1000L, 2000L);
120-
assertThat(result2.toMillis()).isBetween(1000L, 2000L);
121-
assertThat(result3.toMillis()).isBetween(1000L, 2000L);
119+
assertThat(result1.toMillis()).isBetween(200L, 400L);
120+
assertThat(result2.toMillis()).isBetween(200L, 400L);
121+
assertThat(result3.toMillis()).isBetween(200L, 400L);
122122
}
123123

124124
@Test
@@ -146,7 +146,7 @@ void calculateDelay_progressionTest_shouldFollowExponentialPattern() {
146146
// Reset the random seed for consistent results across iterations
147147
fixedRandom.setSeed(42);
148148
Duration delay = ExponentialBackoff.calculateDelay(i, fixedRandom);
149-
long expectedBaseMs = (long) Math.pow(2, i) * 500;
149+
long expectedBaseMs = (long) Math.pow(2, i) * 100;
150150
long expectedMaxMs = Math.min(expectedBaseMs * 2, 120000);
151151

152152
assertThat(delay.toMillis())
@@ -159,7 +159,7 @@ void calculateDelay_progressionTest_shouldFollowExponentialPattern() {
159159
@Test
160160
void calculateDelay_atCapThreshold_shouldCapCorrectly() {
161161
// Given - retry count that would exceed 120s base delay
162-
int retryCount = 8; // 2^8 * 500ms = 128000ms > 120000ms
162+
int retryCount = 11; // 2^11 * 100ms = 204800ms > 120000ms
163163
Random fixedRandom = new Random(42);
164164

165165
// When

src/test/java/dev/openfga/sdk/util/RetryStrategyTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ void calculateRetryDelay_withoutRetryAfterHeader_shouldUseExponentialBackoff() {
224224
Duration result = RetryStrategy.calculateRetryDelay(retryAfterDelay, retryCount);
225225

226226
// Then
227-
// For retry count 1: 2^1 * 500ms = 1000ms base, with jitter between 1000ms and 2000ms
228-
assertThat(result.toMillis()).isBetween(1000L, 2000L);
227+
// For retry count 1: 2^1 * 100ms = 200ms base, with jitter between 200ms and 400ms
228+
assertThat(result.toMillis()).isBetween(200L, 400L);
229229
}
230230

231231
@Test
@@ -238,8 +238,8 @@ void calculateRetryDelay_withEmptyRetryAfterHeader_shouldUseExponentialBackoff()
238238
Duration result = RetryStrategy.calculateRetryDelay(retryAfterDelay, retryCount);
239239

240240
// Then
241-
// For retry count 0: 2^0 * 500ms = 500ms base, with jitter between 500ms and 1000ms
242-
assertThat(result.toMillis()).isBetween(500L, 1000L);
241+
// For retry count 0: 2^0 * 100ms = 100ms base, with jitter between 100ms and 200ms
242+
assertThat(result.toMillis()).isBetween(100L, 200L);
243243
}
244244

245245
@Test

0 commit comments

Comments
 (0)