Skip to content

Commit

Permalink
Merge pull request #5141 from twz123/improve-retrywatcherrors-test
Browse files Browse the repository at this point in the history
Extend inttest RetryWatchErrors unit test
  • Loading branch information
twz123 authored Oct 28, 2024
2 parents 6666ae7 + 03afaac commit f7a6fe3
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion inttest/common/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ limitations under the License.
package common

import (
"fmt"
"io"
"syscall"
"testing"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/stretchr/testify/assert"
)

Expand All @@ -37,9 +41,11 @@ func TestRetryWatchErrors_syscalls(t *testing.T) {
}{
{name: "ECONNRESET", err: syscall.ECONNRESET, expectedDelay: defaultRetryDelay, expectedError: nil},
{name: "ECONNREFUSED", err: syscall.ECONNREFUSED, expectedDelay: defaultRetryDelay, expectedError: nil},
{name: "EOF", err: io.EOF, expectedDelay: defaultRetryDelay, expectedError: nil},
{name: "retryAfter(42)", err: retryAfterError(42), expectedDelay: 42 * time.Second, expectedError: nil},

// The fallthrough case, don't expect retries with this.
{name: "EBADFD", err: syscall.EBADFD, expectedDelay: 0, expectedError: syscall.EBADFD},
{name: "AnError", err: assert.AnError, expectedDelay: 0, expectedError: assert.AnError},
}

for _, test := range tests {
Expand All @@ -52,3 +58,16 @@ func TestRetryWatchErrors_syscalls(t *testing.T) {
})
}
}

type retryAfterError int32

func (e retryAfterError) Error() string {
return fmt.Sprintf("retryAfterError(%d)", int32(e))
}

func (e retryAfterError) Status() metav1.Status {
return metav1.Status{
Reason: metav1.StatusReasonServerTimeout,
Details: &metav1.StatusDetails{RetryAfterSeconds: int32(e)},
}
}

0 comments on commit f7a6fe3

Please sign in to comment.