Skip to content

Commit

Permalink
Fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagobcx committed Feb 2, 2025
1 parent 7427c85 commit 4216470
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions internal/wrappers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var cachedAccessToken string
var cachedAccessTime time.Time
var Domains = make(map[string]struct{})

func retryHTTPRequest(requestFunc func() (*http.Response, error), retries int, baseDelayInMillis time.Duration) (*http.Response, error) {
func retryHTTPRequest(requestFunc func() (*http.Response, error), retries int, baseDelayInMilliSec time.Duration) (*http.Response, error) {

var resp *http.Response
var err error
Expand All @@ -84,7 +84,7 @@ func retryHTTPRequest(requestFunc func() (*http.Response, error), retries int, b
return resp, nil
}
_ = resp.Body.Close()
time.Sleep(baseDelayInMillis * (1 << attempt))
time.Sleep(baseDelayInMilliSec * (1 << attempt))
}
return resp, nil
}
Expand Down
9 changes: 5 additions & 4 deletions internal/wrappers/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/stretchr/testify/assert"
"net/http"
"testing"
"time"
)

type mockReadCloser struct{}
Expand All @@ -25,7 +26,7 @@ func TestRetryHTTPRequest_Success(t *testing.T) {
}, nil
}

resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay*time.Millisecond)
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.Equal(t, http.StatusOK, resp.StatusCode)
Expand All @@ -47,7 +48,7 @@ func TestRetryHTTPRequest_RetryOnBadGateway(t *testing.T) {
}, nil
}

resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay*time.Millisecond)
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.Equal(t, http.StatusOK, resp.StatusCode)
Expand All @@ -59,7 +60,7 @@ func TestRetryHTTPRequest_Fail(t *testing.T) {
return nil, errors.New("network error")
}

resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay*time.Millisecond)
assert.Error(t, err)
assert.Nil(t, resp)
}
Expand All @@ -72,7 +73,7 @@ func TestRetryHTTPRequest_EndWithBadGateway(t *testing.T) {
}, nil
}

resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay*time.Millisecond)
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.Equal(t, http.StatusBadGateway, resp.StatusCode)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package wrappers

import "time"

const (
limitValue = "10000"
retryAttempts = 4
retryDelay = 500 * time.Millisecond
retryDelay = 500
)
17 changes: 9 additions & 8 deletions internal/wrappers/projects-http.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/viper"
"net/http"
"time"

errorConstants "github.com/checkmarx/ast-cli/internal/constants/errors"
commonParams "github.com/checkmarx/ast-cli/internal/params"
Expand All @@ -32,7 +33,7 @@ func (p *ProjectsHTTPWrapper) Create(model *Project) (*ProjectResponseModel, *Er
fn := func() (*http.Response, error) {
return SendHTTPRequest(http.MethodPost, p.path, bytes.NewBuffer(jsonBytes), true, clientTimeout)
}
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay*time.Millisecond)
if err != nil {
return nil, nil, err
}
Expand All @@ -54,7 +55,7 @@ func (p *ProjectsHTTPWrapper) Update(projectID string, model *Project) error {
fn := func() (*http.Response, error) {
return SendHTTPRequest(http.MethodPut, fmt.Sprintf("%s/%s", p.path, projectID), bytes.NewBuffer(jsonBytes), true, clientTimeout)
}
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay*time.Millisecond)
if err != nil {
return err
}
Expand Down Expand Up @@ -87,7 +88,7 @@ func (p *ProjectsHTTPWrapper) UpdateConfiguration(projectID string, configuratio
fn := func() (*http.Response, error) {
return SendHTTPRequestWithQueryParams(http.MethodPatch, "api/configuration/project", params, bytes.NewBuffer(jsonBytes), clientTimeout)
}
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay*time.Millisecond)
if err != nil {
return nil, err
}
Expand All @@ -111,7 +112,7 @@ func (p *ProjectsHTTPWrapper) Get(params map[string]string) (
fn := func() (*http.Response, error) {
return SendHTTPRequestWithQueryParams(http.MethodGet, p.path, params, nil, clientTimeout)
}
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay*time.Millisecond)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -152,7 +153,7 @@ func (p *ProjectsHTTPWrapper) GetByID(projectID string) (
fn := func() (*http.Response, error) {
return SendHTTPRequest(http.MethodGet, p.path+"/"+projectID, http.NoBody, true, clientTimeout)
}
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay*time.Millisecond)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -199,7 +200,7 @@ func (p *ProjectsHTTPWrapper) GetBranchesByID(projectID string, params map[strin
fn := func() (*http.Response, error) {
return SendHTTPRequestWithQueryParams(http.MethodGet, p.path+request, params, nil, clientTimeout)
}
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay*time.Millisecond)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -237,7 +238,7 @@ func (p *ProjectsHTTPWrapper) Delete(projectID string) (*ErrorModel, error) {
fn := func() (*http.Response, error) {
return SendHTTPRequest(http.MethodDelete, p.path+"/"+projectID, http.NoBody, true, clientTimeout)
}
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay*time.Millisecond)
if err != nil {
return nil, err
}
Expand All @@ -258,7 +259,7 @@ func (p *ProjectsHTTPWrapper) Tags() (
fn := func() (*http.Response, error) {
return SendHTTPRequest(http.MethodGet, p.path+"/tags", http.NoBody, true, clientTimeout)
}
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay*time.Millisecond)
if err != nil {
return nil, nil, err
}
Expand Down

0 comments on commit 4216470

Please sign in to comment.