Skip to content

Commit

Permalink
Fix TestBackoffRetry in otlp/internal/retry package (#2562)
Browse files Browse the repository at this point in the history
* Fix TestBackoffRetry in otlp retry pkg

The delay of the retry is within two times a randomization factor (the
back-off time is delay * random number within [1 - factor, 1 + factor].
This means the waitFunc in TestBackoffRetry needs to check the delay is
within an appropriate delta, not equal to configure initial delay.

* Fix delta value

* Fix delta

Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>
  • Loading branch information
MrAlias and MadVikingGod authored Jan 31, 2022
1 parent 2623a46 commit 53ead30
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions exporters/otlp/internal/retry/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ package retry
import (
"context"
"errors"
"math"
"testing"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -131,15 +133,16 @@ func TestBackoffRetry(t *testing.T) {
origWait := waitFunc
var done bool
waitFunc = func(_ context.Context, d time.Duration) error {
assert.Equal(t, delay, d, "retry not backoffed")
delta := math.Ceil(float64(delay)*backoff.DefaultRandomizationFactor) - float64(delay)
assert.InDelta(t, delay, d, delta, "retry not backoffed")
// Try twice to ensure call is attempted again after delay.
if done {
return assert.AnError
}
done = true
return nil
}
defer func() { waitFunc = origWait }()
t.Cleanup(func() { waitFunc = origWait })

ctx := context.Background()
assert.ErrorIs(t, reqFunc(ctx, func(context.Context) error {
Expand Down

0 comments on commit 53ead30

Please sign in to comment.