Skip to content
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

refactor: specify timeout for HTTP calls in run -p/--publish test #42

Merged
merged 1 commit into from
Feb 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions fnet/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ import (
// HTTPGetAndAssert sends an HTTP GET request to the specified URL, asserts the response status code against want, and closes the response body.
func HTTPGetAndAssert(url string, want int, maxRetry int, retryInterval time.Duration) {
var err error
client := http.Client{
Timeout: 5 * time.Second,
}

for i := 0; i < maxRetry; i++ {
// #nosec G107 // it does not matter if url is not a constant for testing.
resp, err := http.Get(url)
resp, err := client.Get(url)
if err != nil {
time.Sleep(retryInterval)
continue
}

defer func() { gomega.Expect(resp.Body.Close()).To(gomega.Succeed()) }()
gomega.Expect(resp.StatusCode).To(gomega.Equal(want))
gomega.Expect(resp.Body.Close()).To(gomega.Succeed())
return
}
ginkgo.Fail(err.Error())
Expand Down