From 03afaacf7cb47ff96b9804f686f465c4d94c9ee9 Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Thu, 4 Apr 2024 09:49:41 +0200 Subject: [PATCH] Extend inttest RetryWatchErrors unit test It used to use syscall.EBADFD, which is not defined on Darwin. Use the generic test error instead, which is platform-independent and does the job just as well. Also, add a test case for the retry delay suggestion detection. Signed-off-by: Tom Wieczorek --- inttest/common/util_test.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/inttest/common/util_test.go b/inttest/common/util_test.go index c807eb9e0c27..f8a41ebde1cb 100644 --- a/inttest/common/util_test.go +++ b/inttest/common/util_test.go @@ -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" ) @@ -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 { @@ -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)}, + } +}