From b7cc094a49e3d348cfc457aa76f1640c86cdcae9 Mon Sep 17 00:00:00 2001 From: roeest Date: Thu, 15 Sep 2022 10:05:18 -0500 Subject: [PATCH] testfix: make apollo federated tracer test more consistent (#2374) * Update tracing_test.go * add missing imports --- .../apollofederatedtracingv1/tracing_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/graphql/handler/apollofederatedtracingv1/tracing_test.go b/graphql/handler/apollofederatedtracingv1/tracing_test.go index 61b8b37c4e..9ed91f91f8 100644 --- a/graphql/handler/apollofederatedtracingv1/tracing_test.go +++ b/graphql/handler/apollofederatedtracingv1/tracing_test.go @@ -1,6 +1,7 @@ package apollofederatedtracingv1_test import ( + "context" "encoding/base64" "encoding/json" "fmt" @@ -8,7 +9,9 @@ import ( "net/http/httptest" "strings" "testing" + "time" + "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql/handler/apollofederatedtracingv1" "github.com/99designs/gqlgen/graphql/handler/apollofederatedtracingv1/generated" "github.com/99designs/gqlgen/graphql/handler/apollotracing" @@ -26,6 +29,7 @@ func TestApolloTracing(t *testing.T) { h := testserver.New() h.AddTransport(transport.POST{}) h.Use(&apollofederatedtracingv1.Tracer{}) + h.Use(&delayMiddleware{}) resp := doRequest(h, http.MethodPost, "/graphql", `{"query":"{ name }"}`) assert.Equal(t, http.StatusOK, resp.Code, resp.Body.String()) @@ -108,3 +112,18 @@ func doRequest(handler http.Handler, method, target, body string) *httptest.Resp handler.ServeHTTP(w, r) return w } + +type delayMiddleware struct{} + +func (*delayMiddleware) InterceptOperation(ctx context.Context, next graphql.OperationHandler) graphql.ResponseHandler { + time.Sleep(time.Millisecond) + return next(ctx) +} + +func (*delayMiddleware) ExtensionName() string { + return "delay" +} + +func (*delayMiddleware) Validate(schema graphql.ExecutableSchema) error { + return nil +}