diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/lib/gitlab/usage/metrics/instrumentations/count_bulk_imports_entities_metric_spec.rb | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/lib/gitlab/usage/metrics/instrumentations/count_bulk_imports_entities_metric_spec.rb')
-rw-r--r-- | spec/lib/gitlab/usage/metrics/instrumentations/count_bulk_imports_entities_metric_spec.rb | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/count_bulk_imports_entities_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/count_bulk_imports_entities_metric_spec.rb new file mode 100644 index 00000000000..b85d5a3ebf9 --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/instrumentations/count_bulk_imports_entities_metric_spec.rb @@ -0,0 +1,106 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountBulkImportsEntitiesMetric do + let_it_be(:user) { create(:user) } + let_it_be(:bulk_import_projects) do + create_list(:bulk_import_entity, 3, source_type: 'project_entity', created_at: 3.weeks.ago) + end + + let_it_be(:bulk_import_groups) do + create_list(:bulk_import_entity, 3, source_type: 'group_entity', created_at: 3.weeks.ago) + end + + let_it_be(:old_bulk_import_project) do + create(:bulk_import_entity, source_type: 'project_entity', created_at: 2.months.ago) + end + + context 'with no source_type' do + context 'with all time frame' do + let(:expected_value) { 7 } + let(:expected_query) do + "SELECT COUNT(\"bulk_import_entities\".\"id\") FROM \"bulk_import_entities\"" + end + + it_behaves_like 'a correct instrumented metric value and query', time_frame: 'all', options: {} + end + + context 'for 28d time frame' do + let(:expected_value) { 6 } + let(:start) { 30.days.ago.to_s(:db) } + let(:finish) { 2.days.ago.to_s(:db) } + let(:expected_query) do + "SELECT COUNT(\"bulk_import_entities\".\"id\") FROM \"bulk_import_entities\""\ + " WHERE \"bulk_import_entities\".\"created_at\" BETWEEN '#{start}' AND '#{finish}'" + end + + it_behaves_like 'a correct instrumented metric value and query', time_frame: '28d', options: {} + end + end + + context 'with invalid source_type' do + it 'raises ArgumentError' do + expect { described_class.new(time_frame: 'all', options: { source_type: 'random' }) } + .to raise_error(ArgumentError, /source_type/) + end + end + + context 'with source_type project_entity' do + context 'with all time frame' do + let(:expected_value) { 4 } + let(:expected_query) do + "SELECT COUNT(\"bulk_import_entities\".\"id\") FROM \"bulk_import_entities\""\ + " WHERE \"bulk_import_entities\".\"source_type\" = 1" + end + + it_behaves_like 'a correct instrumented metric value and query', + time_frame: 'all', + options: { source_type: 'project_entity' } + end + + context 'for 28d time frame' do + let(:expected_value) { 3 } + let(:start) { 30.days.ago.to_s(:db) } + let(:finish) { 2.days.ago.to_s(:db) } + let(:expected_query) do + "SELECT COUNT(\"bulk_import_entities\".\"id\") FROM \"bulk_import_entities\""\ + " WHERE \"bulk_import_entities\".\"created_at\" BETWEEN '#{start}' AND '#{finish}'"\ + " AND \"bulk_import_entities\".\"source_type\" = 1" + end + + it_behaves_like 'a correct instrumented metric value and query', + time_frame: '28d', + options: { source_type: 'project_entity' } + end + end + + context 'with source_type group_entity' do + context 'with all time frame' do + let(:expected_value) { 3 } + let(:expected_query) do + "SELECT COUNT(\"bulk_import_entities\".\"id\") FROM \"bulk_import_entities\""\ + " WHERE \"bulk_import_entities\".\"source_type\" = 0" + end + + it_behaves_like 'a correct instrumented metric value and query', + time_frame: 'all', + options: { source_type: 'group_entity' } + end + + context 'for 28d time frame' do + let(:expected_value) { 3 } + let(:start) { 30.days.ago.to_s(:db) } + let(:finish) { 2.days.ago.to_s(:db) } + let(:expected_query) do + "SELECT COUNT(\"bulk_import_entities\".\"id\") FROM \"bulk_import_entities\""\ + " WHERE \"bulk_import_entities\".\"created_at\" BETWEEN '#{start}' AND '#{finish}'"\ + " AND \"bulk_import_entities\".\"source_type\" = 0" + end + + it_behaves_like 'a correct instrumented metric value and query', + time_frame: '28d', + options: { source_type: 'group_entity' } + end + end +end |