Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/graphql/tracers/timer_tracer_spec.rb')
-rw-r--r--spec/lib/gitlab/graphql/tracers/timer_tracer_spec.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/lib/gitlab/graphql/tracers/timer_tracer_spec.rb b/spec/lib/gitlab/graphql/tracers/timer_tracer_spec.rb
new file mode 100644
index 00000000000..7f837e28772
--- /dev/null
+++ b/spec/lib/gitlab/graphql/tracers/timer_tracer_spec.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+require "fast_spec_helper"
+require "support/graphql/fake_tracer"
+require "support/graphql/fake_query_type"
+
+RSpec.describe Gitlab::Graphql::Tracers::TimerTracer do
+ let(:expected_duration) { 5 }
+ let(:tracer_spy) { spy('tracer_spy') }
+ let(:dummy_schema) do
+ schema = Class.new(GraphQL::Schema) do
+ use Gitlab::Graphql::Tracers::TimerTracer
+
+ query Graphql::FakeQueryType
+ end
+
+ schema.tracer(Graphql::FakeTracer.new(lambda { |*args| tracer_spy.trace(*args) }))
+
+ schema
+ end
+
+ before do
+ current_time = 0
+ allow(Gitlab::Metrics::System).to receive(:monotonic_time) do
+ current_time += expected_duration
+ end
+ end
+
+ it "adds duration_s to the trace metadata", :aggregate_failures do
+ query_string = "query fooOperation { helloWorld }"
+
+ dummy_schema.execute(query_string)
+
+ # "parse" and "execute_query" are just arbitrary trace events
+ expect(tracer_spy).to have_received(:trace).with("parse", {
+ duration_s: expected_duration,
+ query_string: query_string
+ })
+ expect(tracer_spy).to have_received(:trace).with("execute_query", {
+ # greater than expected duration because other calls made to `.monotonic_time` are outside our control
+ duration_s: be >= expected_duration,
+ query: instance_of(GraphQL::Query)
+ })
+ end
+end