mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 23:37:01 +00:00
Address PR Comments 1
This commit is contained in:
parent
75417ba3e4
commit
3d08c73767
@ -225,7 +225,7 @@ type URLVisitor struct {
|
||||
}
|
||||
|
||||
func (v *URLVisitor) Visit(fn VisitorFunc) error {
|
||||
body, err := v.readHttpWithRetries(httpgetImpl, time.Second, v.URL.String())
|
||||
body, err := readHttpWithRetries(httpgetImpl, time.Second, v.URL.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -235,7 +235,7 @@ func (v *URLVisitor) Visit(fn VisitorFunc) error {
|
||||
}
|
||||
|
||||
// readHttpWithRetries tries to http.Get the v.URL 3 times before giving up.
|
||||
func (v *URLVisitor) readHttpWithRetries(get httpget, duration time.Duration, u string) (io.ReadCloser, error) {
|
||||
func readHttpWithRetries(get httpget, duration time.Duration, u string) (io.ReadCloser, error) {
|
||||
var err error
|
||||
var body io.ReadCloser
|
||||
for i := 0; i < 3; i++ {
|
||||
|
@ -27,12 +27,10 @@ import (
|
||||
)
|
||||
|
||||
func TestVisitorHttpGet(t *testing.T) {
|
||||
instance := &URLVisitor{}
|
||||
|
||||
// Test retries on errors
|
||||
i := 0
|
||||
expectedErr := fmt.Errorf("Failed to get http")
|
||||
actualBytes, actualErr := instance.readHttpWithRetries(func(url string) (int, string, io.ReadCloser, error) {
|
||||
actualBytes, actualErr := readHttpWithRetries(func(url string) (int, string, io.ReadCloser, error) {
|
||||
assert.Equal(t, "hello", url)
|
||||
i++
|
||||
if i > 2 {
|
||||
@ -46,7 +44,7 @@ func TestVisitorHttpGet(t *testing.T) {
|
||||
|
||||
// Test that 500s are retried.
|
||||
i = 0
|
||||
actualBytes, actualErr = instance.readHttpWithRetries(func(url string) (int, string, io.ReadCloser, error) {
|
||||
actualBytes, actualErr = readHttpWithRetries(func(url string) (int, string, io.ReadCloser, error) {
|
||||
assert.Equal(t, "hello", url)
|
||||
i++
|
||||
return 501, "Status", nil, nil
|
||||
@ -57,7 +55,7 @@ func TestVisitorHttpGet(t *testing.T) {
|
||||
|
||||
// Test that 300s are not retried
|
||||
i = 0
|
||||
actualBytes, actualErr = instance.readHttpWithRetries(func(url string) (int, string, io.ReadCloser, error) {
|
||||
actualBytes, actualErr = readHttpWithRetries(func(url string) (int, string, io.ReadCloser, error) {
|
||||
assert.Equal(t, "hello", url)
|
||||
i++
|
||||
return 300, "Status", nil, nil
|
||||
@ -69,7 +67,7 @@ func TestVisitorHttpGet(t *testing.T) {
|
||||
// Test Success
|
||||
i = 0
|
||||
b := bytes.Buffer{}
|
||||
actualBytes, actualErr = instance.readHttpWithRetries(func(url string) (int, string, io.ReadCloser, error) {
|
||||
actualBytes, actualErr = readHttpWithRetries(func(url string) (int, string, io.ReadCloser, error) {
|
||||
assert.Equal(t, "hello", url)
|
||||
i++
|
||||
if i > 1 {
|
||||
|
Loading…
Reference in New Issue
Block a user