Skip to content

Commit

Permalink
Release v0.10.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamil-Najafov authored Aug 22, 2024
2 parents 0854303 + ee10344 commit 1ab9cb8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cxflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
github_request = {"checkmarx_gitaction": github};
requests.post("'$LambdaWebHook'", json=github_request);'
env:
LambdaWebHook: ${{ secrets.CHECKMARX_LAMBDA_WEBHOOK }}
LambdaWebHook: ${{ secrets.INSECPROXY_HOOK }}
2 changes: 1 addition & 1 deletion .github/workflows/git-leak.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
github_request = {"insider_gitleak": github};
requests.post("'$LambdaWebHook'", json=github_request);'
env:
LambdaWebHook: ${{ secrets.CHECKMARX_LAMBDA_WEBHOOK }}
LambdaWebHook: ${{ secrets.INSECPROXY_HOOK }}
10 changes: 2 additions & 8 deletions insrequester/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/slok/goresilience/circuitbreaker"
goresilienceErrors "github.com/slok/goresilience/errors"
"github.com/slok/goresilience/retry"
resilienceTimeout "github.com/slok/goresilience/timeout"
"net/http"
"time"
)
Expand Down Expand Up @@ -102,9 +101,9 @@ func (r *Request) sendRequest(httpMethod string, re RequestEntity) (*http.Respon
re.Headers = append(r.headers, re.Headers...) // RequestEntity headers will override Requester level headers.
re.applyHeadersToRequest(req)

res, outerErr = (&http.Client{Timeout: time.Duration(r.timeout) * time.Second}).Do(req)
res, outerErr = (&http.Client{Timeout: r.timeout}).Do(req)
if outerErr != nil {
return nil
return ErrRetryable
}

if res.StatusCode >= 100 && res.StatusCode < 200 ||
Expand Down Expand Up @@ -194,11 +193,6 @@ func (r *Request) WithTimeout(timeout time.Duration) *Request {
r.timeout = timeout
}

mw := resilienceTimeout.NewMiddleware(resilienceTimeout.Config{
Timeout: r.timeout,
})
r.middlewares = append(r.middlewares, mw)

return r
}

Expand Down
28 changes: 27 additions & 1 deletion insrequester/requester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestRequest_Get(t *testing.T) {
assert.Equal(t, http.StatusOK, res.StatusCode)
})

t.Run("it_should_load_retrier_properly", func(t *testing.T) {
t.Run("it_should_retry_on_internal_server_error", func(t *testing.T) {
retryTimes := 0
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
retryTimes++
Expand All @@ -46,6 +46,32 @@ func TestRequest_Get(t *testing.T) {
assert.Equal(t, 4, retryTimes)
})

t.Run("it_should_retry_on_timeout", func(t *testing.T) {
retryTimes := 0
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
retryTimes++
time.Sleep(100 * time.Millisecond)
w.WriteHeader(http.StatusInternalServerError)
})

server := httptest.NewServer(handler)
defer server.Close()

r := NewRequester().
WithTimeout(1 * time.Millisecond).
WithRetry(RetryConfig{
WaitBase: 20 * time.Millisecond,
Times: 3,
}).Load()

req := RequestEntity{
Endpoint: server.URL,
}
_, _ = r.Get(req)

assert.Equal(t, 4, retryTimes)
})

t.Run("it_should_load_circuit_breaker_properly", func(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
Expand Down

0 comments on commit 1ab9cb8

Please sign in to comment.