diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /spec/models/analytics/instance_statistics/measurement_spec.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/models/analytics/instance_statistics/measurement_spec.rb')
-rw-r--r-- | spec/models/analytics/instance_statistics/measurement_spec.rb | 77 |
1 files changed, 61 insertions, 16 deletions
diff --git a/spec/models/analytics/instance_statistics/measurement_spec.rb b/spec/models/analytics/instance_statistics/measurement_spec.rb index 379272cfcb9..dbb16c5ffbe 100644 --- a/spec/models/analytics/instance_statistics/measurement_spec.rb +++ b/spec/models/analytics/instance_statistics/measurement_spec.rb @@ -14,7 +14,7 @@ RSpec.describe Analytics::InstanceStatistics::Measurement, type: :model do describe 'identifiers enum' do it 'maps to the correct values' do - expect(described_class.identifiers).to eq({ + identifiers = { projects: 1, users: 2, issues: 3, @@ -24,8 +24,11 @@ RSpec.describe Analytics::InstanceStatistics::Measurement, type: :model do pipelines_succeeded: 7, pipelines_failed: 8, pipelines_canceled: 9, - pipelines_skipped: 10 - }.with_indifferent_access) + pipelines_skipped: 10, + billable_users: 11 + } + + expect(described_class.identifiers).to eq(identifiers.with_indifferent_access) end end @@ -45,29 +48,71 @@ RSpec.describe Analytics::InstanceStatistics::Measurement, type: :model do it { is_expected.to match_array([measurement_1, measurement_2]) } end - end - describe '#measurement_identifier_values' do - subject { described_class.measurement_identifier_values.count } + describe '.recorded_after' do + subject { described_class.recorded_after(8.days.ago) } - context 'when the `store_ci_pipeline_counts_by_status` feature flag is off' do - let(:expected_count) { Analytics::InstanceStatistics::Measurement.identifiers.size - Analytics::InstanceStatistics::Measurement::EXPERIMENTAL_IDENTIFIERS.size } + it { is_expected.to match_array([measurement_2, measurement_3]) } - before do - stub_feature_flags(store_ci_pipeline_counts_by_status: false) + context 'when nil is given' do + subject { described_class.recorded_after(nil) } + + it 'does not apply filtering' do + expect(subject).to match_array([measurement_1, measurement_2, measurement_3]) + end end + end + + describe '.recorded_before' do + subject { described_class.recorded_before(4.days.ago) } - it { is_expected.to eq(expected_count) } + it { is_expected.to match_array([measurement_1, measurement_3]) } + + context 'when nil is given' do + subject { described_class.recorded_after(nil) } + + it 'does not apply filtering' do + expect(subject).to match_array([measurement_1, measurement_2, measurement_3]) + end + end end + end + + describe '.identifier_query_mapping' do + subject { described_class.identifier_query_mapping } + + it { is_expected.to be_a Hash } + end + + describe '.identifier_min_max_queries' do + subject { described_class.identifier_min_max_queries } + + it { is_expected.to be_a Hash } + end + + describe '.measurement_identifier_values' do + let(:expected_count) { described_class.identifiers.size } + + subject { described_class.measurement_identifier_values.count } + + it { is_expected.to eq(expected_count) } + end - context 'when the `store_ci_pipeline_counts_by_status` feature flag is on' do - let(:expected_count) { Analytics::InstanceStatistics::Measurement.identifiers.size } + describe '.find_latest_or_fallback' do + subject(:count) { described_class.find_latest_or_fallback(:pipelines_skipped).count } - before do - stub_feature_flags(store_ci_pipeline_counts_by_status: true) + context 'with instance statistics' do + let!(:measurement) { create(:instance_statistics_measurement, :pipelines_skipped_count) } + + it 'returns the latest stored measurement' do + expect(count).to eq measurement.count end + end - it { is_expected.to eq(expected_count) } + context 'without instance statistics' do + it 'returns the realtime query of the measurement' do + expect(count).to eq 0 + end end end end |