Skip to content

Commit

Permalink
Enable CLI container port expose test (#7000)
Browse files Browse the repository at this point in the history
# Description

This is to enable CLI container port expose test with the better retry.

## Type of change

- This pull request fixes a bug in Radius and has an approved issue
(issue link required).

Fixes: #3232

---------

Signed-off-by: Young Bu Park <[email protected]>
  • Loading branch information
youngbupark authored Jan 10, 2024
1 parent fcd096e commit be2bc0c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 34 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
53 changes: 19 additions & 34 deletions test/functional/shared/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand All @@ -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
}()

Expand All @@ -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) {
Expand Down

0 comments on commit be2bc0c

Please sign in to comment.