1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
# frozen_string_literal: true
require "spec_helper"
describe GraphQL::Tracing::StatsdTracing do
module TraceMockStatsd
class << self
def time(key)
self.timings << key
yield
end
def timings
@timings
end
def clear
@timings = []
end
end
end
class StatsdTraceTestSchema < GraphQL::Schema
class Thing < GraphQL::Schema::Object
field :str, String
def str; "blah"; end
end
class Query < GraphQL::Schema::Object
field :int, Integer, null: false
def int
1
end
field :thing, Thing
def thing; :thing; end
end
query(Query)
trace_with GraphQL::Tracing::StatsdTrace, statsd: TraceMockStatsd
end
before do
TraceMockStatsd.clear
end
it "gathers timings" do
StatsdTraceTestSchema.execute("query X { int thing { str } }")
expected_timings = [
"graphql.execute_multiplex",
"graphql.analyze_multiplex",
(USING_C_PARSER ? "graphql.lex" : nil),
"graphql.parse",
"graphql.validate",
"graphql.analyze_query",
"graphql.execute_query",
"graphql.authorized.Query",
"graphql.Query.thing",
"graphql.authorized.Thing",
"graphql.execute_query_lazy"
].compact
assert_equal expected_timings, TraceMockStatsd.timings
end
end
|