-
Notifications
You must be signed in to change notification settings - Fork 2
/
retryable_test.go
49 lines (40 loc) · 1 KB
/
retryable_test.go
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
/*
Copyright © 2024 Acronis International GmbH.
Released under MIT license.
*/
package dbkit
import (
"context"
"fmt"
"reflect"
"testing"
"github.com/acronis/go-appkit/retry"
"github.com/cenkalti/backoff/v4"
"github.com/stretchr/testify/assert"
)
func TestMultipleIsRetryError(t *testing.T) {
var called string
// cleanup handlers
oldHandlers := retryableErrors
retryableErrors = map[reflect.Type]retry.IsRetryable{}
defer func() {
retryableErrors = oldHandlers
}()
RegisterIsRetryableFunc(nil, func(e error) bool {
called += "1"
return false
})
RegisterIsRetryableFunc(nil, func(e error) bool {
called += "2"
return false
})
RegisterIsRetryableFunc(nil, func(e error) bool {
called += "3"
return false
})
p := retry.NewExponentialBackoffPolicy(backoff.DefaultInitialInterval, 10)
_ = retry.DoWithRetry(context.Background(), p, GetIsRetryable(nil), nil, func(ctx context.Context) error {
return fmt.Errorf("fake error")
})
assert.Equal(t, "123", called, "Wrong call order")
}