Skip to content

Commit

Permalink
add retries
Browse files Browse the repository at this point in the history
  • Loading branch information
rarguelloF committed Sep 24, 2024
1 parent 53bf242 commit ea59626
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion _integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
github.com/gomodule/redigo v1.9.2
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.1
github.com/hashicorp/go-retryablehttp v0.7.7
github.com/hashicorp/vault/api v1.14.0
github.com/jinzhu/gorm v1.9.16
github.com/labstack/echo/v4 v4.12.0
Expand Down Expand Up @@ -207,7 +208,6 @@ require (
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8 // indirect
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
Expand Down
37 changes: 20 additions & 17 deletions _integration-tests/utils/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/docker/go-connections/nat"
"github.com/google/uuid"
"github.com/hashicorp/go-retryablehttp"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
Expand Down Expand Up @@ -77,25 +78,20 @@ func (a *MockAgent) NewSession(t *testing.T) *Session {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()

req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("http://%s/test/session/start?test_session_token=%s", a.Addr(), session.token.String()), nil)
req, err := retryablehttp.NewRequestWithContext(
ctx,
http.MethodGet,
fmt.Sprintf("http://%s/test/session/start?test_session_token=%s", a.Addr(), session.token.String()),
nil,
)
require.NoError(t, err)

for {
resp, err := http.DefaultClient.Do(req)
if err != nil {
select {
case <-ctx.Done():
require.FailNow(t, "timeout trying to create mock agent test session")
default:
time.Sleep(100 * time.Millisecond)
continue
}
}
if resp.StatusCode != 200 {
require.FailNow(t, "test agent returned non-200 status code")
}
break
}
retryClient := retryablehttp.NewClient()
retryClient.Logger = t
retryClient.RetryMax = 10
resp, err := retryClient.Do(req)
require.NoError(t, err)
require.Equal(t, 200, resp.StatusCode, "received non-success response status code creating test session")

t.Logf("Started test session with ID %s\n", session.token.String())

Expand Down Expand Up @@ -151,6 +147,13 @@ type testLogger struct {
*testing.T
}

// Printf implements retryablehttp.Logger
func (l testLogger) Printf(msg string, args ...interface{}) {
logArgs := append([]interface{}{}, msg, args)
l.T.Log(logArgs...)
}

// Log implements ddtrace.Logger
func (l testLogger) Log(msg string) {
l.T.Log(msg)
}

0 comments on commit ea59626

Please sign in to comment.