Skip to content

Commit

Permalink
refactor: specify timeout for HTTP calls in run -p/--publish test (#42
Browse files Browse the repository at this point in the history
)

Issue #, if available:

*Description of changes:*
Code review fix for #39
*Testing done:*

Yes

- [X] I've reviewed the guidance in CONTRIBUTING.md


#### License Acceptance

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.

Signed-off-by: Vishwas Siravara <[email protected]>
  • Loading branch information
vsiravar authored Feb 28, 2023
1 parent 7a6a6c3 commit cd5f886
Showing 1 changed file with 6 additions and 3 deletions.
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

0 comments on commit cd5f886

Please sign in to comment.