Welcome to mirror list, hosted at ThFree Co, Russian Federation.

track_artifact_report_service_spec.rb « job_artifacts « ci « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6d9fc4c8e34b98d1a54ac5a70999d7dffae76a50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::JobArtifacts::TrackArtifactReportService do
  describe '#execute', :clean_gitlab_redis_shared_state do
    let_it_be(:group) { create(:group, :private) }
    let_it_be(:project) { create(:project, group: group) }
    let_it_be(:user1) { create(:user) }
    let_it_be(:user2) { create(:user) }

    let(:test_event_name) { 'i_testing_test_report_uploaded' }
    let(:counter) { Gitlab::UsageDataCounters::HLLRedisCounter }
    let(:start_time) { 1.week.ago }
    let(:end_time) { 1.week.from_now }

    subject(:track_artifact_report) { described_class.new.execute(pipeline) }

    context 'when pipeline has test reports' do
      let_it_be(:pipeline) { create(:ci_pipeline, project: project, user: user1) }

      before do
        2.times do
          pipeline.builds << build(:ci_build, :test_reports, pipeline: pipeline, project: pipeline.project)
        end
      end

      it 'tracks the event using HLLRedisCounter' do
        allow(Gitlab::UsageDataCounters::HLLRedisCounter)
          .to receive(:track_event)
          .with(test_event_name, values: user1.id)
          .and_call_original

        expect { track_artifact_report }
          .to change {
                counter.unique_events(event_names: test_event_name,
                                      start_date: start_time,
                                      end_date: end_time)
              }
          .by 1
      end
    end

    context 'when pipeline does not have test reports' do
      let_it_be(:pipeline) { create(:ci_empty_pipeline) }

      it 'does not track the event' do
        track_artifact_report

        expect(Gitlab::UsageDataCounters::HLLRedisCounter)
          .not_to receive(:track_event)
          .with(anything, test_event_name)
      end
    end

    context 'when a single user started multiple pipelines with test reports' 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)
          .to receive(:track_event)
          .with(test_event_name, values: user1.id)
          .and_call_original

        allow(Gitlab::UsageDataCounters::HLLRedisCounter)
          .to receive(:track_event)
          .with(test_event_name, values: user1.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,
                                      start_date: start_time,
                                      end_date: end_time)
              }
          .by 1
      end
    end

    context 'when multiple users started multiple pipelines with test reports' 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)
          .to receive(:track_event)
          .with(test_event_name, values: user1.id)
          .and_call_original

        allow(Gitlab::UsageDataCounters::HLLRedisCounter)
          .to receive(:track_event)
          .with(test_event_name, values: user1.id)
          .and_call_original

        allow(Gitlab::UsageDataCounters::HLLRedisCounter)
                 .to receive(:track_event)
                 .with(test_event_name, values: user2.id)
                 .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,
                                      start_date: start_time,
                                      end_date: end_time)
              }
          .by 2
      end
    end
  end
end