Skip to content

Commit

Permalink
tests/e2e/k8s/services/httpecho: Use a fresh connection
Browse files Browse the repository at this point in the history
This commit changes the httpecho client to use a fresh connection per each request.

Signed-off-by: Or Ozeri <[email protected]>
  • Loading branch information
orozery committed Dec 19, 2023
1 parent 4a5b8ba commit 674fe71
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tests/e2e/k8s/services/httpecho/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strconv"
"strings"
"syscall"
"time"

k8serr "k8s.io/apimachinery/pkg/api/errors"

Expand All @@ -38,14 +39,16 @@ func GetEchoValue(cluster *util.KindCluster, server *util.Service) (string, erro
return "", err
}

url := fmt.Sprintf("http://%s", net.JoinHostPort(cluster.IP(), strconv.Itoa(int(port))))
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return "", fmt.Errorf("cannot create request: %w", err)
// fresh client assures a fresh connection
client := &http.Client{
Transport: &http.Transport{
DisableKeepAlives: true,
},
Timeout: 1 * time.Second,
}

req.Close = true
resp, err := http.DefaultClient.Do(req)
url := fmt.Sprintf("http://%s", net.JoinHostPort(cluster.IP(), strconv.Itoa(int(port))))
resp, err := client.Get(url)
if err != nil {
if errors.Is(err, syscall.ECONNREFUSED) {
return "", &services.ConnectionRefusedError{}
Expand Down

0 comments on commit 674fe71

Please sign in to comment.