From 8bbb5eb79bfcc448851883510aa01d99de3f721c Mon Sep 17 00:00:00 2001 From: vvakame Date: Fri, 2 Nov 2018 13:48:56 +0900 Subject: [PATCH] fix some tests --- gqlopencensus/tracer.go | 10 -------- gqlopencensus/tracer_test.go | 45 ++++++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/gqlopencensus/tracer.go b/gqlopencensus/tracer.go index 7c37a064977..74e0cc52789 100644 --- a/gqlopencensus/tracer.go +++ b/gqlopencensus/tracer.go @@ -98,27 +98,17 @@ func (tracerImpl) StartFieldResolverExecution(ctx context.Context, rc *graphql.R } func (tracerImpl) StartFieldChildExecution(ctx context.Context) context.Context { - span := trace.FromContext(ctx) - if !span.IsRecordingEvents() { - return ctx - } return ctx } func (tracerImpl) EndFieldExecution(ctx context.Context) { span := trace.FromContext(ctx) defer span.End() - if !span.IsRecordingEvents() { - return - } } func (tracerImpl) EndOperationExecution(ctx context.Context) { span := trace.FromContext(ctx) defer span.End() - if !span.IsRecordingEvents() { - return - } } func operationName(ctx context.Context) string { diff --git a/gqlopencensus/tracer_test.go b/gqlopencensus/tracer_test.go index 6930f81a0f8..b037707ca70 100644 --- a/gqlopencensus/tracer_test.go +++ b/gqlopencensus/tracer_test.go @@ -59,6 +59,12 @@ func TestTracer(t *testing.T) { "resolver.alias": "F", "resolver.path": "[]", }, + { + "request.query": "query { foobar }", + "request.variables.fizz": "buzz", + "request.complexityLimit": int64(1000), + "request.operationComplexity": int64(100), + }, }, }, { @@ -79,6 +85,12 @@ func TestTracer(t *testing.T) { "resolver.path": "[]", "resource.name": "nameless-operation", }, + { + "request.query": "query { foobar }", + "request.variables.fizz": "buzz", + "request.complexityLimit": int64(1000), + "request.operationComplexity": int64(100), + }, }, }, { @@ -97,21 +109,30 @@ func TestTracer(t *testing.T) { tracer := spec.Tracer ctx := context.Background() - ctx = graphql.WithRequestContext(ctx, &graphql.RequestContext{}) + ctx = graphql.WithRequestContext(ctx, &graphql.RequestContext{ + RawQuery: "query { foobar }", + Variables: map[string]interface{}{ + "fizz": "buzz", + }, + ComplexityLimit: 1000, + OperationComplexity: 100, + }) ctx, _ = trace.StartSpan(ctx, "test", trace.WithSampler(spec.Sampler)) ctx = tracer.StartOperationExecution(ctx) - ctx = tracer.StartFieldExecution(ctx, graphql.CollectedField{ - Field: &ast.Field{ - Name: "F", - Alias: "F", - ObjectDefinition: &ast.Definition{ - Name: "OD", + { + ctx := tracer.StartFieldExecution(ctx, graphql.CollectedField{ + Field: &ast.Field{ + Name: "F", + Alias: "F", + ObjectDefinition: &ast.Definition{ + Name: "OD", + }, }, - }, - }) - ctx = tracer.StartFieldResolverExecution(ctx, &graphql.ResolverContext{}) - ctx = tracer.StartFieldChildExecution(ctx) - tracer.EndFieldExecution(ctx) + }) + ctx = tracer.StartFieldResolverExecution(ctx, &graphql.ResolverContext{}) + ctx = tracer.StartFieldChildExecution(ctx) + tracer.EndFieldExecution(ctx) + } tracer.EndOperationExecution(ctx) if len(spec.ExpectedAttrs) == 0 && len(exporter.Spans) != 0 {