-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable CLI container port expose test #7000
Merged
youngbupark
merged 10 commits into
radius-project:main
from
youngbupark:youngp/enable-cli-test
Jan 10, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8864e99
enable cli test
youngbupark 3d220a5
Merge branch 'main' into youngp/enable-cli-test
youngbupark de5ceaa
fix test
youngbupark 73b0246
adjust retry
youngbupark c8c4be8
revert
youngbupark a692894
add more log
youngbupark 07a8a3c
adjust
youngbupark 94c4397
improve code
youngbupark 59ef24f
reorder
youngbupark 60ee783
adjust
youngbupark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The port could be a const |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks much better than the old code! |
||
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) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think this test is still flaky?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know, but I believe it will barely happen. The previous retry logic was linear back-off with 1 second interval. total 10 seconds might be too short to run container or app up completely in some cases. in new change, I used 5 second interval with jitter. This will give enough time to run container or app up.