diff --git a/go.mod b/go.mod index 828ce5081c..919b7d40f8 100644 --- a/go.mod +++ b/go.mod @@ -94,6 +94,7 @@ require ( require ( github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/hashicorp/go-retryablehttp v0.7.5 // indirect github.com/stretchr/objx v0.5.1 // indirect github.com/tidwall/gjson v1.14.0 // indirect github.com/tidwall/match v1.1.1 // indirect diff --git a/go.sum b/go.sum index 52829d83dc..571a187043 100644 --- a/go.sum +++ b/go.sum @@ -576,11 +576,14 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= +github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT9yvm0e+Nd5M= +github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= diff --git a/test/functional/shared/cli/cli_test.go b/test/functional/shared/cli/cli_test.go index f675f9c6fa..ae38a5db3f 100644 --- a/test/functional/shared/cli/cli_test.go +++ b/test/functional/shared/cli/cli_test.go @@ -33,6 +33,7 @@ import ( "testing" "time" + "github.com/hashicorp/go-retryablehttp" "github.com/radius-project/radius/pkg/cli/bicep" "github.com/radius-project/radius/pkg/cli/clients" "github.com/radius-project/radius/pkg/cli/cmd/radinit" @@ -228,7 +229,6 @@ func verifyCLIBasics(ctx context.Context, t *testing.T, test shared.RPTest) { }) t.Run("Validate rad resource expose Container", func(t *testing.T) { - t.Skip("https://github.com/radius-project/radius/issues/3232") port, err := GetAvailablePort() require.NoError(t, err) @@ -237,7 +237,8 @@ func verifyCLIBasics(ctx context.Context, t *testing.T, test shared.RPTest) { done := make(chan error) go func() { - _, err = cli.ResourceExpose(child, appName, containerName, port, 3000) + output, err := cli.ResourceExpose(child, appName, containerName, port, 3000) + t.Logf("ResourceExpose - output: %s", output) done <- err }() @@ -254,40 +255,24 @@ func verifyCLIBasics(ctx context.Context, t *testing.T, test shared.RPTest) { // callHealthEndpointOnLocalPort calls the magpie health endpoint '/healthz' with retries. It will fail the // test if the exceed the number of retries without success. func callHealthEndpointOnLocalPort(t *testing.T, retries int, port int) { - for i := 0; i < retries; i++ { - url := fmt.Sprintf("http://localhost:%d/healthz", port) - t.Logf("making request to %s", url) - response, err := http.Get(url) - if err != nil { - if i == retries-1 { - // last retry failed, report failure - require.NoError(t, err, "failed to get connect to resource after %d retries", retries) - } - t.Logf("got error %s", err.Error()) - time.Sleep(1 * time.Second) - continue - } - if response.Body != nil { - defer response.Body.Close() - } - - if response.StatusCode > 299 || response.StatusCode < 200 { - if i == retries-1 { - // last retry failed, report failure - require.NoError(t, err, "status code was a bad response after %d retries %d", retries, response.StatusCode) - } - t.Logf("got status %d", response.StatusCode) - time.Sleep(1 * time.Second) - continue - } + healthzURL := fmt.Sprintf("http://localhost:%d/healthz", port) + + retryClient := retryablehttp.NewClient() + retryClient.RetryMax = retries + retryClient.RetryWaitMin = 5 * time.Second + retryClient.RetryWaitMax = 20 * time.Second + retryClient.Backoff = retryablehttp.LinearJitterBackoff + retryClient.RequestLogHook = func(_ retryablehttp.Logger, req *http.Request, retry int) { + t.Logf("retry calling healthz endpoint %s, retry: %d", healthzURL, retry) + } - defer response.Body.Close() - content, err := io.ReadAll(response.Body) - require.NoError(t, err) + resp, err := retryClient.Get(healthzURL) + require.NoError(t, err, "failed to get connect to resource after %d retries", retries) + defer resp.Body.Close() + content, err := io.ReadAll(resp.Body) + require.NoError(t, err) - t.Logf("[response] %s", string(content)) - return - } + t.Logf("[response] %s", string(content)) } func Test_Run_Logger(t *testing.T) {