Skip to content

Commit

Permalink
Test is passing
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
  • Loading branch information
slinkydeveloper committed Jun 22, 2021
1 parent 3126ebe commit 407cd61
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
15 changes: 7 additions & 8 deletions pkg/kncloudevents/message_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,22 @@ func TestHTTPMessageSenderSendWithRetriesWithSingleRequestTimeout(t *testing.T)
var n int32
server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
newVal := atomic.AddInt32(&n, 1)
if newVal == 5 {
if newVal >= 5 {
writer.WriteHeader(http.StatusOK)
} else {
// Let's add one more second
time.Sleep(timeout + time.Second)
time.Sleep(timeout)
writer.WriteHeader(http.StatusAccepted)
}
}))
defer server.Close()

sender := &HTTPMessageSender{
Client: getClient(),
}
config := &RetryConfig{
RetryMax: 5,
CheckRetry: func(ctx context.Context, resp *http.Response, err error) (bool, error) {
return true, nil
},
RetryMax: 5,
CheckRetry: RetryIfGreaterThan300,
Backoff: func(attemptNum int, resp *http.Response) time.Duration {
return time.Millisecond
},
Expand All @@ -189,10 +188,10 @@ func TestHTTPMessageSenderSendWithRetriesWithSingleRequestTimeout(t *testing.T)
require.NoError(t, err)

got, err := sender.SendWithRetries(request, config)
require.NoError(t, err)

require.Equal(t, http.StatusOK, got.StatusCode)
require.Equal(t, 5, int(atomic.LoadInt32(&n)))
require.NoError(t, err)
require.Equal(t, http.StatusOK, got.StatusCode)
}

func TestRetriesOnNetworkErrors(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/kncloudevents/retries.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ type RetryConfig struct {

CheckRetry CheckRetry
Backoff Backoff

// RequestTimeout represents the timeout of the single request
RequestTimeout time.Duration
}

func NoRetries() RetryConfig {
Expand Down

0 comments on commit 407cd61

Please sign in to comment.