mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +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 {
|
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 {
|
if err != nil {
|
||||||
return err
|
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.
|
// 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 err error
|
||||||
var body io.ReadCloser
|
var body io.ReadCloser
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
|
@ -27,12 +27,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestVisitorHttpGet(t *testing.T) {
|
func TestVisitorHttpGet(t *testing.T) {
|
||||||
instance := &URLVisitor{}
|
|
||||||
|
|
||||||
// Test retries on errors
|
// Test retries on errors
|
||||||
i := 0
|
i := 0
|
||||||
expectedErr := fmt.Errorf("Failed to get http")
|
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)
|
assert.Equal(t, "hello", url)
|
||||||
i++
|
i++
|
||||||
if i > 2 {
|
if i > 2 {
|
||||||
@ -46,7 +44,7 @@ func TestVisitorHttpGet(t *testing.T) {
|
|||||||
|
|
||||||
// Test that 500s are retried.
|
// Test that 500s are retried.
|
||||||
i = 0
|
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)
|
assert.Equal(t, "hello", url)
|
||||||
i++
|
i++
|
||||||
return 501, "Status", nil, nil
|
return 501, "Status", nil, nil
|
||||||
@ -57,7 +55,7 @@ func TestVisitorHttpGet(t *testing.T) {
|
|||||||
|
|
||||||
// Test that 300s are not retried
|
// Test that 300s are not retried
|
||||||
i = 0
|
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)
|
assert.Equal(t, "hello", url)
|
||||||
i++
|
i++
|
||||||
return 300, "Status", nil, nil
|
return 300, "Status", nil, nil
|
||||||
@ -69,7 +67,7 @@ func TestVisitorHttpGet(t *testing.T) {
|
|||||||
// Test Success
|
// Test Success
|
||||||
i = 0
|
i = 0
|
||||||
b := bytes.Buffer{}
|
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)
|
assert.Equal(t, "hello", url)
|
||||||
i++
|
i++
|
||||||
if i > 1 {
|
if i > 1 {
|
||||||
|
Loading…
Reference in New Issue
Block a user