diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
commit | 7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 (patch) | |
tree | 5bdc2229f5198d516781f8d24eace62fc7e589e9 /spec/services/ci/job_artifacts/track_artifact_report_service_spec.rb | |
parent | 185b095e93520f96e9cfc31d9c3e69b498cdab7c (diff) |
Add latest changes from gitlab-org/gitlab@15-6-stable-eev15.6.0-rc42
Diffstat (limited to 'spec/services/ci/job_artifacts/track_artifact_report_service_spec.rb')
-rw-r--r-- | spec/services/ci/job_artifacts/track_artifact_report_service_spec.rb | 127 |
1 files changed, 102 insertions, 25 deletions
diff --git a/spec/services/ci/job_artifacts/track_artifact_report_service_spec.rb b/spec/services/ci/job_artifacts/track_artifact_report_service_spec.rb index 6d9fc4c8e34..d4d56825e1f 100644 --- a/spec/services/ci/job_artifacts/track_artifact_report_service_spec.rb +++ b/spec/services/ci/job_artifacts/track_artifact_report_service_spec.rb @@ -9,7 +9,9 @@ RSpec.describe Ci::JobArtifacts::TrackArtifactReportService do let_it_be(:user1) { create(:user) } let_it_be(:user2) { create(:user) } - let(:test_event_name) { 'i_testing_test_report_uploaded' } + let(:test_event_name_1) { 'i_testing_test_report_uploaded' } + let(:test_event_name_2) { 'i_testing_coverage_report_uploaded' } + let(:counter) { Gitlab::UsageDataCounters::HLLRedisCounter } let(:start_time) { 1.week.ago } let(:end_time) { 1.week.from_now } @@ -25,15 +27,15 @@ RSpec.describe Ci::JobArtifacts::TrackArtifactReportService do end end - it 'tracks the event using HLLRedisCounter' do - allow(Gitlab::UsageDataCounters::HLLRedisCounter) + it 'tracks the test event using HLLRedisCounter' do + expect(Gitlab::UsageDataCounters::HLLRedisCounter) .to receive(:track_event) - .with(test_event_name, values: user1.id) + .with(test_event_name_1, values: user1.id) .and_call_original expect { track_artifact_report } .to change { - counter.unique_events(event_names: test_event_name, + counter.unique_events(event_names: test_event_name_1, start_date: start_time, end_date: end_time) } @@ -44,12 +46,20 @@ RSpec.describe Ci::JobArtifacts::TrackArtifactReportService do context 'when pipeline does not have test reports' do let_it_be(:pipeline) { create(:ci_empty_pipeline) } - it 'does not track the event' do + it 'does not track the test event' do track_artifact_report expect(Gitlab::UsageDataCounters::HLLRedisCounter) .not_to receive(:track_event) - .with(anything, test_event_name) + .with(anything, test_event_name_1) + end + + it 'does not track the coverage test event' do + track_artifact_report + + expect(Gitlab::UsageDataCounters::HLLRedisCounter) + .not_to receive(:track_event) + .with(anything, test_event_name_2) end end @@ -57,15 +67,15 @@ RSpec.describe Ci::JobArtifacts::TrackArtifactReportService do let_it_be(:pipeline1) { create(:ci_pipeline, :with_test_reports, project: project, user: user1) } let_it_be(:pipeline2) { create(:ci_pipeline, :with_test_reports, project: project, user: user1) } - it 'tracks all pipelines using HLLRedisCounter by one user_id' do - allow(Gitlab::UsageDataCounters::HLLRedisCounter) + it 'tracks all pipelines using HLLRedisCounter by one user_id for the test event' do + expect(Gitlab::UsageDataCounters::HLLRedisCounter) .to receive(:track_event) - .with(test_event_name, values: user1.id) + .with(test_event_name_1, values: user1.id) .and_call_original - allow(Gitlab::UsageDataCounters::HLLRedisCounter) + expect(Gitlab::UsageDataCounters::HLLRedisCounter) .to receive(:track_event) - .with(test_event_name, values: user1.id) + .with(test_event_name_1, values: user1.id) .and_call_original expect do @@ -73,7 +83,7 @@ RSpec.describe Ci::JobArtifacts::TrackArtifactReportService do described_class.new.execute(pipeline2) end .to change { - counter.unique_events(event_names: test_event_name, + counter.unique_events(event_names: test_event_name_1, start_date: start_time, end_date: end_time) } @@ -85,25 +95,92 @@ RSpec.describe Ci::JobArtifacts::TrackArtifactReportService do let_it_be(:pipeline1) { create(:ci_pipeline, :with_test_reports, project: project, user: user1) } let_it_be(:pipeline2) { create(:ci_pipeline, :with_test_reports, project: project, user: user2) } - it 'tracks all pipelines using HLLRedisCounter by multiple users' do - allow(Gitlab::UsageDataCounters::HLLRedisCounter) + it 'tracks all pipelines using HLLRedisCounter by multiple users for test reports' do + expect(Gitlab::UsageDataCounters::HLLRedisCounter) + .to receive(:track_event) + .with(test_event_name_1, values: user1.id) + .and_call_original + + expect(Gitlab::UsageDataCounters::HLLRedisCounter) + .to receive(:track_event) + .with(test_event_name_1, values: user2.id) + .and_call_original + + expect do + described_class.new.execute(pipeline1) + described_class.new.execute(pipeline2) + end + .to change { + counter.unique_events(event_names: test_event_name_1, + start_date: start_time, + end_date: end_time) + } + .by 2 + end + end + + context 'when pipeline has coverage test reports' do + let_it_be(:pipeline) { create(:ci_pipeline, project: project, user: user1) } + + before do + 2.times do + pipeline.builds << build(:ci_build, :coverage_reports, pipeline: pipeline, project: pipeline.project) + end + end + + it 'tracks the coverage test event using HLLRedisCounter' do + expect(Gitlab::UsageDataCounters::HLLRedisCounter) .to receive(:track_event) - .with(test_event_name, values: user1.id) + .with(test_event_name_2, values: user1.id) .and_call_original - allow(Gitlab::UsageDataCounters::HLLRedisCounter) + expect { track_artifact_report } + .to change { + counter.unique_events(event_names: test_event_name_2, + start_date: start_time, + end_date: end_time) + } + .by 1 + end + end + + context 'when a single user started multiple pipelines with coverage reports' do + let_it_be(:pipeline1) { create(:ci_pipeline, :with_coverage_reports, project: project, user: user1) } + let_it_be(:pipeline2) { create(:ci_pipeline, :with_coverage_reports, project: project, user: user1) } + + it 'tracks all pipelines using HLLRedisCounter by one user_id for the coverage test event' do + expect(Gitlab::UsageDataCounters::HLLRedisCounter) .to receive(:track_event) - .with(test_event_name, values: user1.id) + .with(test_event_name_2, values: user1.id) + .twice .and_call_original - allow(Gitlab::UsageDataCounters::HLLRedisCounter) - .to receive(:track_event) - .with(test_event_name, values: user2.id) - .and_call_original + expect do + described_class.new.execute(pipeline1) + described_class.new.execute(pipeline2) + end + .to change { + counter.unique_events(event_names: test_event_name_2, + start_date: start_time, + end_date: end_time) + } + .by 1 + end + end + + context 'when multiple users started multiple pipelines with coverage test reports' do + let_it_be(:pipeline1) { create(:ci_pipeline, :with_coverage_reports, project: project, user: user1) } + let_it_be(:pipeline2) { create(:ci_pipeline, :with_coverage_reports, project: project, user: user2) } + + it 'tracks all pipelines using HLLRedisCounter by multiple users for coverage test reports' do + expect(Gitlab::UsageDataCounters::HLLRedisCounter) + .to receive(:track_event) + .with(test_event_name_2, values: user1.id) + .and_call_original - allow(Gitlab::UsageDataCounters::HLLRedisCounter) + expect(Gitlab::UsageDataCounters::HLLRedisCounter) .to receive(:track_event) - .with(test_event_name, values: user2.id) + .with(test_event_name_2, values: user2.id) .and_call_original expect do @@ -111,7 +188,7 @@ RSpec.describe Ci::JobArtifacts::TrackArtifactReportService do described_class.new.execute(pipeline2) end .to change { - counter.unique_events(event_names: test_event_name, + counter.unique_events(event_names: test_event_name_2, start_date: start_time, end_date: end_time) } |