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: HTTP/2 routing suite #981

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
51 changes: 51 additions & 0 deletions http2_routing/grpc_routing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package http2_routing

import (
"context"
"fmt"
"time"

protobuff "github.com/cloudfoundry/cf-acceptance-tests/helpers/assets/test"
. "github.com/cloudfoundry/cf-acceptance-tests/helpers/v3_helpers"
"google.golang.org/grpc"

. "github.com/cloudfoundry/cf-acceptance-tests/cats_suite_helpers"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/app_helpers"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/random_name"
"github.com/cloudfoundry/cf-test-helpers/v2/cf"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = HTTP2RoutingDescribe("gRPC apps", func() {
var appName string

BeforeEach(func() {
appName = random_name.CATSRandomName("APP")

pushArgs := app_helpers.GRPCWithArgs(appName, "--no-route", "-m", DEFAULT_MEMORY_LIMIT)
Expect(cf.Cf(pushArgs...).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))

domain := Config.GetAppsDomain()
Expect(cf.Cf("map-route", domain, "--hostname", appName, "--app-protocol", "http2").Wait()).To(Exit(0))
})

It("can serve gRPC traffic (requires HTTP/2 for all hops)", func() {
domain := Config.GetAppsDomain()
target := fmt.Sprintf("%s.%s:443", appName, domain)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

conn, err := grpc.DialContext(ctx, target, grpc.WithBlock(), grpc.FailOnNonTempDialError(true))
Expect(err).ToNot(HaveOccurred())
defer conn.Close()

tc := protobuff.NewTestClient(conn)

resp, err := tc.Run(ctx, &protobuff.Request{})
Expect(err).ToNot(HaveOccurred())
Expect(resp.GetBody()).To(Equal("Hello"))
})
})
88 changes: 10 additions & 78 deletions http2_routing/http2_routing.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
package http2_routing

import (
"context"
"crypto/tls"
"time"

protobuff "github.com/cloudfoundry/cf-acceptance-tests/helpers/assets/test"
. "github.com/cloudfoundry/cf-acceptance-tests/helpers/v3_helpers"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"

. "github.com/cloudfoundry/cf-acceptance-tests/cats_suite_helpers"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/app_helpers"
Expand All @@ -20,81 +13,20 @@ import (
. "github.com/onsi/gomega/gexec"
)

var _ = HTTP2RoutingDescribe("HTTP/2 Routing", func() {
Context("when a destination only supports HTTP/2", func() {
It("routes traffic to that destination over HTTP/2", func() {
appName := random_name.CATSRandomName("APP")

Expect(cf.Cf(app_helpers.HTTP2WithArgs(
appName,
"--no-route",
"-m", DEFAULT_MEMORY_LIMIT)...).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))

appGUID := app_helpers.GetAppGuid(appName)
var _ = HTTP2RoutingDescribe("HTTP/2 apps", func() {
var appName string

Expect(cf.Cf("create-route", Config.GetAppsDomain(),
"--hostname", appName,
).Wait()).To(Exit(0))
BeforeEach(func() {
appName = random_name.CATSRandomName("APP")

destination := Destination{
App: App{
GUID: appGUID,
},
Protocol: "http2",
}
InsertDestinations(GetRouteGuid(appName), []Destination{destination})
pushArgs := app_helpers.HTTP2WithArgs(appName, "--no-route", "-m", DEFAULT_MEMORY_LIMIT)
Expect(cf.Cf(pushArgs...).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))

Eventually(func() string {
return helpers.CurlAppRoot(Config, appName)
}).Should(ContainSubstring("Hello"))
})
domain := Config.GetAppsDomain()
Expect(cf.Cf("map-route", domain, "--hostname", appName, "--app-protocol", "http2").Wait()).To(Exit(0))
})

Context("when a destination serves gRPC", func() {
It("successfully routes the gRPC traffic (requires HTTP/2 for all hops)", func() {
appName := random_name.CATSRandomName("APP")

Expect(cf.Cf(app_helpers.GRPCWithArgs(
appName,
"--no-route",
"-m", DEFAULT_MEMORY_LIMIT)...).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))

appGUID := app_helpers.GetAppGuid(appName)

appsDomain := Config.GetAppsDomain()
Expect(cf.Cf("create-route", appsDomain,
"--hostname", appName,
).Wait()).To(Exit(0))

destination := Destination{
App: App{
GUID: appGUID,
},
Protocol: "http2",
}
InsertDestinations(GetRouteGuid(appName), []Destination{destination})

appURI := appName + "." + appsDomain + ":443"

tlsConfig := tls.Config{InsecureSkipVerify: true}
creds := credentials.NewTLS(&tlsConfig)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
conn, err := grpc.DialContext(
ctx,
appURI,
grpc.WithTransportCredentials(creds),
grpc.WithBlock(),
grpc.FailOnNonTempDialError(true),
)
Expect(err).ToNot(HaveOccurred())
defer conn.Close()

client := protobuff.NewTestClient(conn)
response, err := client.Run(ctx, &protobuff.Request{})
Expect(err).ToNot(HaveOccurred())
Expect(response.GetBody()).To(Equal("Hello"))
})
It("receive routed traffic over HTTP/2", func() {
Eventually(helpers.CurlAppRoot).WithArguments(Config, appName).Should(ContainSubstring("Hello"))
})
})