Skip to content

Commit

Permalink
testfix: make apollo federated tracer test more consistent (#2374)
Browse files Browse the repository at this point in the history
* Update tracing_test.go

* add missing imports
  • Loading branch information
roeest committed Sep 15, 2022
1 parent d096fb9 commit b7cc094
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions graphql/handler/apollofederatedtracingv1/tracing_test.go
@@ -1,14 +1,17 @@
package apollofederatedtracingv1_test

import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
"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"
Expand All @@ -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())
Expand Down Expand Up @@ -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
}

0 comments on commit b7cc094

Please sign in to comment.