Skip to content

Commit

Permalink
Extend inttest RetryWatchErrors unit test
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
twz123 committed Oct 23, 2024
1 parent ba5c8d1 commit 03afaac
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 03afaac

Please sign in to comment.