summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/graphql
diff options
context:
space:
mode:
authorcharlieablett <cablett@gitlab.com>2019-05-02 19:09:10 +1200
committercharlieablett <cablett@gitlab.com>2019-05-30 18:27:28 +1200
commit2a1006416748950805294793f1bc8d6fa7435eea (patch)
treed54dfd57be5ddd7b9e5fc4e9d1fe271c88c41f3e /spec/lib/gitlab/graphql
parent2c011cb5b452409db7fe1c810f1ad7440a6cedce (diff)
downloadgitlab-ce-2a1006416748950805294793f1bc8d6fa7435eea.tar.gz
Restructure complexity analyzer
Remove instance variables for class re-use, test individual methods, use `monotonic_time`
Diffstat (limited to 'spec/lib/gitlab/graphql')
-rw-r--r--spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb40
1 files changed, 31 insertions, 9 deletions
diff --git a/spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb b/spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb
index 53a1d7f8e42..f85a3a206b1 100644
--- a/spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb
+++ b/spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb
@@ -7,21 +7,43 @@ describe Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer do
subject { described_class.new }
let(:query_string) { "abc" }
let(:provided_variables) { { a: 1, b: 2, c: 3 } }
+ let!(:now) { Gitlab::Metrics::System.monotonic_time }
let(:complexity) { 4 }
let(:depth) { 2 }
- let(:expected_hash) do
- { query_string: query_string,
+ let(:initial_values) do
+ { time_started: now,
+ query_string: query_string,
variables: provided_variables,
- complexity: complexity,
- depth: depth }
+ complexity: nil,
+ depth: nil,
+ duration: nil }
+ end
+ before do
+ allow(Gitlab::Metrics::System).to receive(:monotonic_time).and_return(now)
end
- it 'assembles a hash' do
- query = OpenStruct.new(query_string: query_string, provided_variables: provided_variables)
-
- subject.initial_value(query)
+ describe '#initial_value' do
+ it 'assembles a hash with initial values' do
+ query = OpenStruct.new(query_string: query_string, provided_variables: provided_variables)
- expect(subject.instance_variable_get("@info_hash")).to eq expected_hash
+ expect(subject.initial_value(query)).to eq initial_values
+ end
end
+ describe '#call' do
+ before do
+ # some statements to fudge the complexity and depth
+ end
+
+ it 'sets the complexity and depth' do
+ expected_hash = { time_started: now,
+ query_string: query_string,
+ variables: provided_variables,
+ complexity: nil,
+ depth: depth,
+ duration: complexity }
+
+ expect(subject.call(initial_values, nil, nil)).to eq expected_hash
+ end
+ end
end