Skip to content

Commit

Permalink
allow grpc and websocket e2e tests to pass when --ingressendpoint is … (
Browse files Browse the repository at this point in the history
#4047)

* allow grpc and websocket e2e tests to pass when --ingressendpoint is supplied

* PR review feedback

* address PR comments
  • Loading branch information
chaodaiG authored and knative-prow-robot committed May 9, 2019
1 parent f74e18c commit b4bc050
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
31 changes: 25 additions & 6 deletions test/e2e/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ package e2e
import (
"context"
"io"
"strconv"
"strings"
"testing"
"time"

Expand All @@ -35,21 +37,35 @@ import (

type grpcTest func(*testing.T, *test.ResourceObjects, *test.Clients, string, string)

// hasPort checks if a URL contains a port number
func hasPort(u string) bool {
parts := strings.Split(u, ":")
_, err := strconv.Atoi(parts[len(parts)-1])
return err == nil
}

func dial(host, domain string) (*grpc.ClientConn, error) {
if !hasPort(host) {
host = host + ":80"
}
if !hasPort(domain) {
domain = domain + ":80"
}

if host != domain {
// The host to connect and the domain accepted differ.
// We need to do grpc.WithAuthority(...) here.
return grpc.Dial(
host+":80",
grpc.WithAuthority(domain+":80"),
host,
grpc.WithAuthority(domain),
grpc.WithInsecure(),
// Retrying DNS errors to avoid .xip.io issues.
grpc.WithDefaultCallOptions(grpc.FailFast(false)),
)
}
// This is a more preferred usage of the go-grpc client.
return grpc.Dial(
host+":80",
host,
grpc.WithInsecure(),
// Retrying DNS errors to avoid .xip.io issues.
grpc.WithDefaultCallOptions(grpc.FailFast(false)),
Expand Down Expand Up @@ -169,9 +185,12 @@ func testGRPC(t *testing.T, f grpcTest) {

host := &domain
if !test.ServingFlags.ResolvableDomain {
host, err = ingress.GetIngressEndpoint(clients.KubeClient.Kube)
if err != nil {
t.Fatalf("Could not get service endpoint: %v", err)
host = &pkgTest.Flags.IngressEndpoint
if pkgTest.Flags.IngressEndpoint == "" {
host, err = ingress.GetIngressEndpoint(clients.KubeClient.Kube)
if err != nil {
t.Fatalf("Could not get service endpoint: %v", err)
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions test/e2e/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

"github.com/gorilla/websocket"
pkgTest "github.com/knative/pkg/test"
ingress "github.com/knative/pkg/test/ingress"
rnames "github.com/knative/serving/pkg/reconciler/revision/resources/names"
"github.com/knative/serving/test"
Expand Down Expand Up @@ -67,9 +68,12 @@ func connect(t *testing.T, ingressIP string, domain string) (*websocket.Conn, er
}

func validateWebSocketConnection(t *testing.T, clients *test.Clients, names test.ResourceNames) error {
gatewayIP, err := ingress.GetIngressEndpoint(clients.KubeClient.Kube)
if err != nil {
return err
var err error
gatewayIP := &pkgTest.Flags.IngressEndpoint
if pkgTest.Flags.IngressEndpoint == "" {
if gatewayIP, err = ingress.GetIngressEndpoint(clients.KubeClient.Kube); err != nil {
return err
}
}

// Establish the websocket connection.
Expand Down

0 comments on commit b4bc050

Please sign in to comment.