diff options
author | charlieablett <cablett@gitlab.com> | 2019-05-02 19:09:10 +1200 |
---|---|---|
committer | charlieablett <cablett@gitlab.com> | 2019-05-30 18:27:28 +1200 |
commit | 2a1006416748950805294793f1bc8d6fa7435eea (patch) | |
tree | d54dfd57be5ddd7b9e5fc4e9d1fe271c88c41f3e /spec/lib/gitlab | |
parent | 2c011cb5b452409db7fe1c810f1ad7440a6cedce (diff) | |
download | gitlab-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')
-rw-r--r-- | spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb | 40 |
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 |