mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-04-15 11:36:44 +02:00
Fix TestBackoffRetry in otlp/internal/retry package (#2562)
* 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>
This commit is contained in:
parent
2623a46dfe
commit
53ead308b8
@ -17,9 +17,11 @@ package retry
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/cenkalti/backoff/v4"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -131,7 +133,8 @@ func TestBackoffRetry(t *testing.T) {
|
|||||||
origWait := waitFunc
|
origWait := waitFunc
|
||||||
var done bool
|
var done bool
|
||||||
waitFunc = func(_ context.Context, d time.Duration) error {
|
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.
|
// Try twice to ensure call is attempted again after delay.
|
||||||
if done {
|
if done {
|
||||||
return assert.AnError
|
return assert.AnError
|
||||||
@ -139,7 +142,7 @@ func TestBackoffRetry(t *testing.T) {
|
|||||||
done = true
|
done = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
defer func() { waitFunc = origWait }()
|
t.Cleanup(func() { waitFunc = origWait })
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
assert.ErrorIs(t, reqFunc(ctx, func(context.Context) error {
|
assert.ErrorIs(t, reqFunc(ctx, func(context.Context) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user