-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathretryable_test.go
50 lines (42 loc) · 1.17 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
50
/*
Copyright © 2024 Acronis International GmbH.
Released under MIT license.
*/
package dbkit
import (
"context"
"fmt"
"testing"
"time"
"github.com/acronis/go-appkit/retry"
"github.com/stretchr/testify/assert"
)
func TestMultipleIsRetryError(t *testing.T) {
retryPolicy := retry.NewExponentialBackoffPolicy(time.Millisecond*50, 10)
UnregisterAllIsRetryableFuncs(nil)
// test multiple IsRetryable functions
called := ""
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
})
_ = retry.DoWithRetry(context.Background(), retryPolicy, GetIsRetryable(nil), nil, func(ctx context.Context) error {
return fmt.Errorf("fake error")
})
assert.Equal(t, "123", called, "Wrong call order")
// unregister all functions and test that no one is called
UnregisterAllIsRetryableFuncs(nil)
called = ""
_ = retry.DoWithRetry(context.Background(), retryPolicy, GetIsRetryable(nil), nil, func(ctx context.Context) error {
return fmt.Errorf("fake error")
})
assert.Equal(t, "", called)
}