diff options
Diffstat (limited to 'spec/lib/gitlab/usage/metrics')
-rw-r--r-- | spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/usage/metrics/instrumentations/generic_metric_spec.rb | 40 |
2 files changed, 38 insertions, 6 deletions
diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb index 0a32bdb95d3..4d84423cde4 100644 --- a/spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb +++ b/spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb @@ -19,7 +19,7 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::DatabaseMetric do let_it_be(:issues) { Issue.all } before do - allow(ActiveRecord::Base.connection).to receive(:transaction_open?).and_return(false) + allow(Issue.connection).to receive(:transaction_open?).and_return(false) end it 'calculates a correct result' do @@ -82,7 +82,7 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::DatabaseMetric do end.new(time_frame: 'all') end - it 'calculates a correct result' do + it 'calculates a correct result', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/349762' do expect(subject.value).to be_within(Gitlab::Database::PostgresHll::BatchDistinctCounter::ERROR_RATE).percent_of(3) end diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/generic_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/generic_metric_spec.rb index c8cb1bb4373..cc4df696b37 100644 --- a/spec/lib/gitlab/usage/metrics/instrumentations/generic_metric_spec.rb +++ b/spec/lib/gitlab/usage/metrics/instrumentations/generic_metric_spec.rb @@ -17,9 +17,25 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::GenericMetric do end context 'when raising an exception' do - it 'return the custom fallback' do + before do + allow(Gitlab::ErrorTracking).to receive(:should_raise_for_dev?).and_return(should_raise_for_dev) expect(ApplicationRecord.database).to receive(:version).and_raise('Error') - expect(subject.value).to eq(custom_fallback) + end + + context 'with should_raise_for_dev? false' do + let(:should_raise_for_dev) { false } + + it 'return the custom fallback' do + expect(subject.value).to eq(custom_fallback) + end + end + + context 'with should_raise_for_dev? true' do + let(:should_raise_for_dev) { true } + + it 'raises an error' do + expect { subject.value }.to raise_error('Error') + end end end end @@ -38,9 +54,25 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::GenericMetric do end context 'when raising an exception' do - it 'return the default fallback' do + before do + allow(Gitlab::ErrorTracking).to receive(:should_raise_for_dev?).and_return(should_raise_for_dev) expect(ApplicationRecord.database).to receive(:version).and_raise('Error') - expect(subject.value).to eq(described_class::FALLBACK) + end + + context 'with should_raise_for_dev? false' do + let(:should_raise_for_dev) { false } + + it 'return the default fallback' do + expect(subject.value).to eq(described_class::FALLBACK) + end + end + + context 'with should_raise_for_dev? true' do + let(:should_raise_for_dev) { true } + + it 'raises an error' do + expect { subject.value }.to raise_error('Error') + end end end end |