diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 00:08:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 00:08:35 +0300 |
commit | 93003eb1155fdc2ce078fa03c74d7f15e83a80de (patch) | |
tree | 31c2dbc649c83c1979fc5f2493c4c31ea9d22182 /spec/workers/projects | |
parent | 1038f06b8654472558735796de54647888dabec4 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers/projects')
-rw-r--r-- | spec/workers/projects/refresh_build_artifacts_size_statistics_worker_spec.rb | 96 | ||||
-rw-r--r-- | spec/workers/projects/schedule_refresh_build_artifacts_size_statistics_worker_spec.rb | 17 |
2 files changed, 113 insertions, 0 deletions
diff --git a/spec/workers/projects/refresh_build_artifacts_size_statistics_worker_spec.rb b/spec/workers/projects/refresh_build_artifacts_size_statistics_worker_spec.rb new file mode 100644 index 00000000000..4a6a525a5a7 --- /dev/null +++ b/spec/workers/projects/refresh_build_artifacts_size_statistics_worker_spec.rb @@ -0,0 +1,96 @@ +# 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 } + + context 'when all projects_build_artifacts_size_refresh flags are enabled' do + it { is_expected.to eq(described_class::MAX_RUNNING_HIGH) } + end + + context 'when projects_build_artifacts_size_refresh_high flags is disabled' do + before do + stub_feature_flags(projects_build_artifacts_size_refresh_high: false) + end + + it { is_expected.to eq(described_class::MAX_RUNNING_MEDIUM) } + end + + context 'when projects_build_artifacts_size_refresh_high and projects_build_artifacts_size_refresh_medium flags are disabled' do + before do + stub_feature_flags(projects_build_artifacts_size_refresh_high: false) + stub_feature_flags(projects_build_artifacts_size_refresh_medium: false) + end + + it { is_expected.to eq(described_class::MAX_RUNNING_LOW) } + end + + context 'when all projects_build_artifacts_size_refresh flags are disabled' do + before do + stub_feature_flags(projects_build_artifacts_size_refresh_low: false) + stub_feature_flags(projects_build_artifacts_size_refresh_medium: false) + stub_feature_flags(projects_build_artifacts_size_refresh_high: false) + end + + it { is_expected.to eq(0) } + end + end +end diff --git a/spec/workers/projects/schedule_refresh_build_artifacts_size_statistics_worker_spec.rb b/spec/workers/projects/schedule_refresh_build_artifacts_size_statistics_worker_spec.rb new file mode 100644 index 00000000000..b5775f37678 --- /dev/null +++ b/spec/workers/projects/schedule_refresh_build_artifacts_size_statistics_worker_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Projects::ScheduleRefreshBuildArtifactsSizeStatisticsWorker do + subject(:worker) { described_class.new } + + describe '#perform' do + include_examples 'an idempotent worker' do + it 'schedules Projects::RefreshBuildArtifactsSizeStatisticsWorker to be performed with capacity' do + expect(Projects::RefreshBuildArtifactsSizeStatisticsWorker).to receive(:perform_with_capacity).twice + + subject + end + end + end +end |