-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
58 changed files
with
11,340 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package netutil | ||
|
||
import ( | ||
"errors" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestRetrier_Do(t *testing.T) { | ||
r := NewRetrier(time.Millisecond*100,time.Millisecond*500,2) | ||
c := 0 | ||
threshold := 2 | ||
f := func() error { | ||
c++ | ||
if c >= threshold { | ||
return nil | ||
} | ||
|
||
return errors.New("foo") | ||
} | ||
|
||
t.Run("should retry", func(t *testing.T) { | ||
c = 0 | ||
|
||
err := r.Do(f) | ||
require.NoError(t, err) | ||
}) | ||
|
||
t.Run("if retry reaches threshold should error", func(t *testing.T){ | ||
c = 0 | ||
threshold = 4 | ||
defer func() { | ||
threshold = 2 | ||
}() | ||
|
||
err := r.Do(f) | ||
require.Error(t, err) | ||
}) | ||
|
||
t.Run("if function times out should error", func(t *testing.T) { | ||
c = 0 | ||
slowF := func() error { | ||
time.Sleep(time.Second) | ||
return nil | ||
} | ||
|
||
err := r.Do(slowF) | ||
require.Error(t, err) | ||
}) | ||
|
||
t.Run("should return whitelisted errors if any instead of retry", func(t *testing.T){ | ||
bar := errors.New("bar") | ||
wR := NewRetrier(50*time.Millisecond, time.Second, 2).WithErrWhitelist(bar) | ||
barF := func() error { | ||
return bar | ||
} | ||
|
||
err := wR.Do(barF) | ||
require.EqualError(t, err, bar.Error()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.