-
Notifications
You must be signed in to change notification settings - Fork 854
Expand file tree
/
Copy pathretry_test.go
More file actions
78 lines (66 loc) · 1.61 KB
/
retry_test.go
File metadata and controls
78 lines (66 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package transport
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/thanos-io/thanos/pkg/pool"
"github.com/weaveworks/common/httpgrpc"
"go.uber.org/atomic"
"github.com/cortexproject/cortex/pkg/storegateway"
)
func TestRetry(t *testing.T) {
tries := atomic.NewInt64(3)
r := NewRetry(3, nil)
ctx := context.Background()
res, err := r.Do(ctx, func() (*httpgrpc.HTTPResponse, error) {
try := tries.Dec()
if try > 1 {
return &httpgrpc.HTTPResponse{
Code: 500,
}, nil
}
return &httpgrpc.HTTPResponse{
Code: 200,
}, nil
})
require.NoError(t, err)
require.Equal(t, int32(200), res.Code)
}
func TestNoRetryOnChunkPoolExhaustion(t *testing.T) {
tries := atomic.NewInt64(3)
r := NewRetry(3, nil)
ctx := context.Background()
res, err := r.Do(ctx, func() (*httpgrpc.HTTPResponse, error) {
try := tries.Dec()
if try > 1 {
return &httpgrpc.HTTPResponse{
Code: 500,
Body: []byte(pool.ErrPoolExhausted.Error()),
}, nil
}
return &httpgrpc.HTTPResponse{
Code: 200,
}, nil
})
require.NoError(t, err)
require.Equal(t, int32(500), res.Code)
}
func TestNoRetryOnMaxConcurrentBytesLimitExceeded(t *testing.T) {
tries := atomic.NewInt64(3)
r := NewRetry(3, nil)
ctx := context.Background()
res, err := r.Do(ctx, func() (*httpgrpc.HTTPResponse, error) {
try := tries.Dec()
if try > 1 {
return &httpgrpc.HTTPResponse{
Code: 500,
Body: []byte(storegateway.ErrMaxConcurrentBytesLimitExceeded.Error()),
}, nil
}
return &httpgrpc.HTTPResponse{
Code: 200,
}, nil
})
require.NoError(t, err)
require.Equal(t, int32(500), res.Code)
}