Skip to content

Commit 3dc8afb

Browse files
committed
RUM-8038: Reset backoff to minimum on upload success
1 parent 1bec5b7 commit 3dc8afb

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/data/upload/DefaultUploadSchedulerStrategy.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import com.datadog.android.core.internal.data.upload.DataOkHttpUploader.Companio
1212
import java.io.IOException
1313
import java.util.concurrent.ConcurrentHashMap
1414
import java.util.concurrent.TimeUnit
15-
import kotlin.math.max
1615
import kotlin.math.min
1716
import kotlin.math.roundToLong
1817

@@ -32,7 +31,7 @@ internal class DefaultUploadSchedulerStrategy(
3231
): Long {
3332
val previousDelay = currentDelays.getOrPut(featureName) { uploadConfiguration.defaultDelayMs }
3433
val updatedDelay = if (uploadAttempts > 0 && throwable == null && lastStatusCode == HTTP_ACCEPTED) {
35-
decreaseInterval(previousDelay)
34+
uploadConfiguration.minDelayMs
3635
} else {
3736
increaseInterval(previousDelay, throwable)
3837
}
@@ -44,12 +43,6 @@ internal class DefaultUploadSchedulerStrategy(
4443

4544
// region Internal
4645

47-
private fun decreaseInterval(previousDelay: Long): Long {
48-
@Suppress("UnsafeThirdPartyFunctionCall") // not a NaN
49-
val newDelayMs = (previousDelay * DECREASE_PERCENT).roundToLong()
50-
return max(uploadConfiguration.minDelayMs, newDelayMs)
51-
}
52-
5346
private fun increaseInterval(previousDelay: Long, throwable: Throwable?): Long {
5447
@Suppress("UnsafeThirdPartyFunctionCall") // not a NaN
5548
val newDelayMs = (previousDelay * INCREASE_PERCENT).roundToLong()
@@ -67,7 +60,6 @@ internal class DefaultUploadSchedulerStrategy(
6760
// endregion
6861

6962
companion object {
70-
internal const val DECREASE_PERCENT = 0.90
7163
internal const val INCREASE_PERCENT = 1.10
7264
internal val NETWORK_ERROR_DELAY_MS = TimeUnit.MINUTES.toMillis(1) // 1 minute delay
7365
}

dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/data/upload/DefaultUploadSchedulerStrategyTest.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ import java.io.IOException
2626
@ForgeConfiguration(Configurator::class)
2727
internal class DefaultUploadSchedulerStrategyTest {
2828

29-
lateinit var testedStrategy: UploadSchedulerStrategy
29+
private lateinit var testedStrategy: UploadSchedulerStrategy
3030

3131
@Forgery
3232
lateinit var fakeConfiguration: DataUploadConfiguration
3333

3434
@StringForgery
3535
lateinit var fakeFeatureName: String
3636

37-
var initialDelay = 0L
37+
private var initialDelay = 0L
3838

3939
@BeforeEach
4040
fun `set up`() {
@@ -43,7 +43,7 @@ internal class DefaultUploadSchedulerStrategyTest {
4343
}
4444

4545
@Test
46-
fun `M decrease delay W getMsDelayUntilNextUpload() {successful attempt}`(
46+
fun `M decrease delay to minimum W getMsDelayUntilNextUpload() {successful attempt}`(
4747
@IntForgery(1, 128) repeats: Int,
4848
@IntForgery(1, 64) attempts: Int
4949
) {
@@ -54,8 +54,7 @@ internal class DefaultUploadSchedulerStrategyTest {
5454
repeat(repeats) { delay = testedStrategy.getMsDelayUntilNextUpload(fakeFeatureName, attempts, 202, null) }
5555

5656
// Then
57-
assertThat(delay).isLessThan(initialDelay)
58-
assertThat(delay).isGreaterThanOrEqualTo(fakeConfiguration.minDelayMs)
57+
assertThat(delay).isEqualTo(fakeConfiguration.minDelayMs)
5958
}
6059

6160
@Test

0 commit comments

Comments
 (0)