Skip to content

Commit

Permalink
fix test race by only stubbing now where we need to
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Jan 15, 2020
1 parent 8dbce3c commit 4dd1008
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
21 changes: 21 additions & 0 deletions graphql/handler/apollotracing/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"net/http/httptest"
"strings"
"testing"
"time"

"github.com/99designs/gqlgen/graphql"

"github.com/99designs/gqlgen/graphql/handler/apollotracing"
"github.com/99designs/gqlgen/graphql/handler/extension"
Expand All @@ -18,6 +21,15 @@ import (
)

func TestApolloTracing(t *testing.T) {
now := time.Unix(0, 0)

graphql.Now = func() time.Time {
defer func() {
now = now.Add(100 * time.Nanosecond)
}()
return now
}

h := testserver.New()
h.AddTransport(transport.POST{})
h.Use(apollotracing.Tracer{})
Expand Down Expand Up @@ -54,6 +66,15 @@ func TestApolloTracing(t *testing.T) {
}

func TestApolloTracing_withFail(t *testing.T) {
now := time.Unix(0, 0)

graphql.Now = func() time.Time {
defer func() {
now = now.Add(100 * time.Nanosecond)
}()
return now
}

h := testserver.New()
h.AddTransport(transport.POST{})
h.Use(extension.AutomaticPersistedQuery{Cache: lru.New(100)})
Expand Down
8 changes: 0 additions & 8 deletions graphql/handler/testserver/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ import (
// a generated server, but it aims to be good enough to test the handler package without relying on codegen.
func New() *TestServer {
next := make(chan struct{})
now := time.Unix(0, 0)

graphql.Now = func() time.Time {
defer func() {
now = now.Add(100 * time.Nanosecond)
}()
return now
}

schema := gqlparser.MustLoadSchema(&ast.Source{Input: `
type Query {
Expand Down

0 comments on commit 4dd1008

Please sign in to comment.