Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/operation/interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ func (i *Interval) SetIntervalGauge(rowsModified int) {
i.noActivityCount++

if i.noActivityCount >= i.incBackoffCount {
i.currInterval *= 2
if i.currInterval > i.maxInterval/2 {
i.currInterval = i.maxInterval
} else {
i.currInterval *= 2
}
i.noActivityCount = 0
}
}
Expand Down
20 changes: 20 additions & 0 deletions internal/operation/interval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,26 @@ func TestInterval_SetIntervalGauge_BackoffMechanism(t *testing.T) {
assert.Equal(t, 200*time.Millisecond, interval.currInterval, "Should double again after 3 more zero-row updates")
}

func TestInterval_SetIntervalGauge_CapsBeforeOverflow(t *testing.T) {
const maxDuration = time.Duration(1<<63 - 1)

interval := &Interval{
resourceId: testResourceID,
maxJitter: 0,
startInterval: time.Second,
currInterval: maxDuration/2 + 1,
maxInterval: maxDuration,
noActivityCount: 0,
incBackoffCount: 1,
repo: v1.NewNoOpIntervalSettingsRepository(),
}

interval.SetIntervalGauge(0)

assert.Equal(t, maxDuration, interval.currInterval, "Should cap before doubling overflows")
assert.Equal(t, 0, interval.noActivityCount, "Should reset count after backoff")
}

func TestInterval_SetIntervalGauge_ConcurrentAccess(t *testing.T) {
interval := &Interval{
resourceId: testResourceID,
Expand Down
Loading