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

refresh_build_artifacts_size_statistics_worker_spec.rb « projects « workers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c7e45e7e4d7fac92c6fd3ff185543ba494d557ef (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Projects::RefreshBuildArtifactsSizeStatisticsWorker do
  let(:worker) { described_class.new }

  describe '#perform_work' do
    before do
      expect_next_instance_of(Projects::RefreshBuildArtifactsSizeStatisticsService) do |instance|
        expect(instance).to receive(:execute).and_return(refresh)
      end
    end

    context 'when refresh job is present' do
      let(:refresh) do
        build(
          :project_build_artifacts_size_refresh,
          :running,
          project_id: 77,
          last_job_artifact_id: 123
        )
      end

      it 'logs refresh information' do
        expect(worker).to receive(:log_extra_metadata_on_done).with(:project_id, refresh.project_id)
        expect(worker).to receive(:log_extra_metadata_on_done).with(:last_job_artifact_id, refresh.last_job_artifact_id)
        expect(worker).to receive(:log_extra_metadata_on_done).with(:last_batch, refresh.destroyed?)
        expect(worker).to receive(:log_extra_metadata_on_done).with(:refresh_started_at, refresh.refresh_started_at)

        worker.perform_work
      end
    end

    context 'when refresh job is not present' do
      let(:refresh) { nil }

      it 'logs refresh information' do
        expect(worker).not_to receive(:log_extra_metadata_on_done)

        worker.perform_work
      end
    end
  end

  describe '#remaining_work_count' do
    subject { worker.remaining_work_count }

    context 'and there are remaining refresh jobs' do
      before do
        create_list(:project_build_artifacts_size_refresh, 2, :pending)
      end

      it { is_expected.to eq(1) }
    end

    context 'and there are no remaining refresh jobs' do
      it { is_expected.to eq(0) }
    end
  end

  describe '#max_running_jobs' do
    subject { worker.max_running_jobs }

    it { is_expected.to eq(10) }

    context 'when projects_build_artifacts_size_refresh flag is disabled' do
      before do
        stub_feature_flags(projects_build_artifacts_size_refresh: false)
      end

      it { is_expected.to eq(0) }
    end
  end
end