diff options
Diffstat (limited to 'spec/lib/gitlab/usage/metrics/aggregates/sources/postgres_hll_spec.rb')
-rw-r--r-- | spec/lib/gitlab/usage/metrics/aggregates/sources/postgres_hll_spec.rb | 60 |
1 files changed, 44 insertions, 16 deletions
diff --git a/spec/lib/gitlab/usage/metrics/aggregates/sources/postgres_hll_spec.rb b/spec/lib/gitlab/usage/metrics/aggregates/sources/postgres_hll_spec.rb index db878828cd6..1ae4c9414dd 100644 --- a/spec/lib/gitlab/usage/metrics/aggregates/sources/postgres_hll_spec.rb +++ b/spec/lib/gitlab/usage/metrics/aggregates/sources/postgres_hll_spec.rb @@ -12,11 +12,7 @@ RSpec.describe Gitlab::Usage::Metrics::Aggregates::Sources::PostgresHll, :clean_ let(:metric_2) { 'metric_2' } let(:metric_names) { [metric_1, metric_2] } - describe '.calculate_events_union' do - subject(:calculate_metrics_union) do - described_class.calculate_metrics_union(metric_names: metric_names, start_date: start_date, end_date: end_date, recorded_at: recorded_at) - end - + describe 'metric calculations' do before do [ { @@ -36,23 +32,55 @@ RSpec.describe Gitlab::Usage::Metrics::Aggregates::Sources::PostgresHll, :clean_ end end - it 'returns the number of unique events in the union of all metrics' do - expect(calculate_metrics_union.round(2)).to eq(3.12) - end + describe '.calculate_events_union' do + subject(:calculate_metrics_union) do + described_class.calculate_metrics_union(metric_names: metric_names, start_date: start_date, end_date: end_date, recorded_at: recorded_at) + end + + it 'returns the number of unique events in the union of all metrics' do + expect(calculate_metrics_union.round(2)).to eq(3.12) + end + + context 'when there is no aggregated data saved' do + let(:metric_names) { [metric_1, 'i do not have any records'] } + + it 'raises error when union data is missing' do + expect { calculate_metrics_union }.to raise_error Gitlab::Usage::Metrics::Aggregates::Sources::UnionNotAvailable + end + end - context 'when there is no aggregated data saved' do - let(:metric_names) { [metric_1, 'i do not have any records'] } + context 'when there is only one metric defined as aggregated' do + let(:metric_names) { [metric_1] } - it 'raises error when union data is missing' do - expect { calculate_metrics_union }.to raise_error Gitlab::Usage::Metrics::Aggregates::Sources::UnionNotAvailable + it 'returns the number of unique events for that metric' do + expect(calculate_metrics_union.round(2)).to eq(2.08) + end end end - context 'when there is only one metric defined as aggregated' do - let(:metric_names) { [metric_1] } + describe '.calculate_metrics_intersections' do + subject(:calculate_metrics_intersections) do + described_class.calculate_metrics_intersections(metric_names: metric_names, start_date: start_date, end_date: end_date, recorded_at: recorded_at) + end + + it 'returns the number of common events in the intersection of all metrics' do + expect(calculate_metrics_intersections.round(2)).to eq(1.04) + end + + context 'when there is no aggregated data saved' do + let(:metric_names) { [metric_1, 'i do not have any records'] } - it 'returns the number of unique events for that metric' do - expect(calculate_metrics_union.round(2)).to eq(2.08) + it 'raises error when union data is missing' do + expect { calculate_metrics_intersections }.to raise_error Gitlab::Usage::Metrics::Aggregates::Sources::UnionNotAvailable + end + end + + context 'when there is only one metric defined in aggregate' do + let(:metric_names) { [metric_1] } + + it 'returns the number of common/unique events for the intersection of that metric' do + expect(calculate_metrics_intersections.round(2)).to eq(2.08) + end end end end |