summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Provaznik <jprovaznik@gitlab.com>2019-04-03 12:53:43 +0200
committerJan Provaznik <jprovaznik@gitlab.com>2019-04-03 17:22:57 +0200
commit2556799eb116c17c942f9ced22d933fab0662e7f (patch)
treed71e1bd07bb2566f984195419c3ea8aa2d5df1f7
parent97cfe2ef5d6ee36443c16670f6eae01be507a947 (diff)
downloadgitlab-ce-jprovazn-graphql-prometheus.tar.gz
Fixed graphql specjprovazn-graphql-prometheus
GraphQL uses a singleton for `.execute` method so it's possible that `GitlabSchema.execute` is served by an instance of GitlabSchema which was initialized on a previous spec and that instance doesn't have histogram stubbed. To avoid this, we pass stubbed tracer as an explicit parameter to `GitlabSchema.execute`.
-rw-r--r--spec/lib/gitlab/graphql/tracing_spec.rb18
1 files changed, 8 insertions, 10 deletions
diff --git a/spec/lib/gitlab/graphql/tracing_spec.rb b/spec/lib/gitlab/graphql/tracing_spec.rb
index 6bae737d0f6..7300a9a572e 100644
--- a/spec/lib/gitlab/graphql/tracing_spec.rb
+++ b/spec/lib/gitlab/graphql/tracing_spec.rb
@@ -3,17 +3,15 @@
require 'spec_helper'
describe Gitlab::Graphql::Tracing do
- let!(:graphql_duration_seconds) { double('Gitlab::Metrics::NullMetric') }
-
- before do
- allow(Gitlab::Metrics)
- .to receive(:histogram)
- .with(:graphql_duration_seconds, 'GraphQL execution time')
- .and_return(graphql_duration_seconds)
- end
+ let(:graphql_duration_seconds_histogram) { double('Gitlab::Metrics::NullMetric') }
it 'updates graphql histogram with expected labels' do
query = 'query { users { id } }'
+ tracer = described_class.new
+
+ allow(tracer)
+ .to receive(:graphql_duration_seconds)
+ .and_return(graphql_duration_seconds_histogram)
expect_metric('graphql.lex', 'lex')
expect_metric('graphql.parse', 'parse')
@@ -22,13 +20,13 @@ describe Gitlab::Graphql::Tracing do
expect_metric('graphql.execute', 'execute_query_lazy')
expect_metric('graphql.execute', 'execute_multiplex')
- GitlabSchema.execute(query)
+ GitlabSchema.execute(query, context: { tracers: [tracer] })
end
private
def expect_metric(platform_key, key)
- expect(graphql_duration_seconds)
+ expect(graphql_duration_seconds_histogram)
.to receive(:observe)
.with({ platform_key: platform_key, key: key }, be > 0.0)
end