Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed Nov 2, 2018
1 parent 256e741 commit 8bbb5eb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
10 changes: 0 additions & 10 deletions gqlopencensus/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
45 changes: 33 additions & 12 deletions gqlopencensus/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
},
},
{
Expand All @@ -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),
},
},
},
{
Expand All @@ -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 {
Expand Down

0 comments on commit 8bbb5eb

Please sign in to comment.