mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 08:55:24 +00:00
15c93f02ea
Related to #7130, this adds logic to retry native notarization up to three times if it fails for some reason. Since we're adding retries in various places, I added a new package under pkg for this purpose.
42 lines
803 B
Go
42 lines
803 B
Go
package retry
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var errTest = errors.New("test error")
|
|
|
|
func TestRetryDo(t *testing.T) {
|
|
t.Run("WithMaxAttempts only performs the operation the configured number of times", func(t *testing.T) {
|
|
count := 0
|
|
max := 3
|
|
|
|
err := Do(func() error {
|
|
count++
|
|
return errTest
|
|
}, WithMaxAttempts(max), WithInterval(1*time.Millisecond))
|
|
|
|
require.ErrorIs(t, errTest, err)
|
|
require.Equal(t, max, count)
|
|
})
|
|
|
|
t.Run("operations are run an unlimited number of times by default", func(t *testing.T) {
|
|
count := 0
|
|
max := 10
|
|
|
|
err := Do(func() error {
|
|
if count++; count != max {
|
|
return errTest
|
|
}
|
|
return nil
|
|
}, WithInterval(1*time.Millisecond))
|
|
|
|
require.NoError(t, err)
|
|
require.Equal(t, max, count)
|
|
})
|
|
}
|