File: statsd_trace_spec.rb

package info (click to toggle)
ruby-graphql 2.5.19-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 13,868 kB
  • sloc: ruby: 80,420; ansic: 1,808; yacc: 845; javascript: 480; makefile: 6
file content (64 lines) | stat: -rw-r--r-- 1,284 bytes parent folder | download
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
# 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 timing(key, ms)
        self.timings << key
      end

      attr_reader :timings

      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",
      (USING_C_PARSER ? "graphql.lex" : nil),
      "graphql.parse",
      "graphql.validate",
      "graphql.analyze",
      "graphql.authorized.Query",
      "graphql.Query.thing",
      "graphql.authorized.Thing",
    ].compact
    assert_equal expected_timings, TraceMockStatsd.timings
  end
end