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

testfix: make apollo federated tracer test more consistent #2374

Merged
merged 3 commits into from Sep 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
}