From 9216b55239cd6da74d9301eb70ffdc6805ae3691 Mon Sep 17 00:00:00 2001 From: Carson Long Date: Wed, 22 Nov 2023 21:01:17 -0800 Subject: [PATCH] Refactor HTTP/2 Routing suite - Reword descriptions for clarity. - Use `cf map-route` with new `--app-protocol` flag to create an HTTP/2 route for the apps. --- http2_routing/grpc_routing.go | 51 ++++++++++++++++++++ http2_routing/http2_routing.go | 88 ++++------------------------------ 2 files changed, 61 insertions(+), 78 deletions(-) create mode 100644 http2_routing/grpc_routing.go diff --git a/http2_routing/grpc_routing.go b/http2_routing/grpc_routing.go new file mode 100644 index 000000000..5c2e90118 --- /dev/null +++ b/http2_routing/grpc_routing.go @@ -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")) + }) +}) diff --git a/http2_routing/http2_routing.go b/http2_routing/http2_routing.go index f931f0dd0..94c3ddb37 100644 --- a/http2_routing/http2_routing.go +++ b/http2_routing/http2_routing.go @@ -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" @@ -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")) }) })