diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-25 15:07:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-25 15:07:22 +0300 |
commit | fc4faf47ac4e5f1ddc40640c42c32405c38c9455 (patch) | |
tree | f6d8642f577eda485efc0570300b5da28f0a7dfe /spec/workers | |
parent | 91a7f1897e7cb14d60c2aaf3afa76ebdc879d939 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers')
10 files changed, 123 insertions, 95 deletions
diff --git a/spec/workers/ci/pending_builds/update_group_worker_spec.rb b/spec/workers/ci/pending_builds/update_group_worker_spec.rb index c16262c0502..bd278f4c923 100644 --- a/spec/workers/ci/pending_builds/update_group_worker_spec.rb +++ b/spec/workers/ci/pending_builds/update_group_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::PendingBuilds::UpdateGroupWorker, feature_category: :subgroups do +RSpec.describe Ci::PendingBuilds::UpdateGroupWorker, feature_category: :groups_and_projects do describe '#perform' do let(:worker) { described_class.new } diff --git a/spec/workers/ci/pending_builds/update_project_worker_spec.rb b/spec/workers/ci/pending_builds/update_project_worker_spec.rb index 281b4fb920b..d50209fba90 100644 --- a/spec/workers/ci/pending_builds/update_project_worker_spec.rb +++ b/spec/workers/ci/pending_builds/update_project_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::PendingBuilds::UpdateProjectWorker, feature_category: :projects do +RSpec.describe Ci::PendingBuilds::UpdateProjectWorker, feature_category: :groups_and_projects do describe '#perform' do let(:worker) { described_class.new } diff --git a/spec/workers/disallow_two_factor_for_group_worker_spec.rb b/spec/workers/disallow_two_factor_for_group_worker_spec.rb index c732f8a3d00..a7a5a4ae279 100644 --- a/spec/workers/disallow_two_factor_for_group_worker_spec.rb +++ b/spec/workers/disallow_two_factor_for_group_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DisallowTwoFactorForGroupWorker, feature_category: :subgroups do +RSpec.describe DisallowTwoFactorForGroupWorker, feature_category: :groups_and_projects do let_it_be(:group) { create(:group, require_two_factor_authentication: true) } let_it_be(:user) { create(:user, require_two_factor_authentication_from_group: true) } diff --git a/spec/workers/disallow_two_factor_for_subgroups_worker_spec.rb b/spec/workers/disallow_two_factor_for_subgroups_worker_spec.rb index 7584355deab..e5871ba8c21 100644 --- a/spec/workers/disallow_two_factor_for_subgroups_worker_spec.rb +++ b/spec/workers/disallow_two_factor_for_subgroups_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DisallowTwoFactorForSubgroupsWorker, feature_category: :subgroups do +RSpec.describe DisallowTwoFactorForSubgroupsWorker, feature_category: :groups_and_projects do let_it_be(:group) { create(:group) } let_it_be(:subgroup_with_2fa) { create(:group, parent: group, require_two_factor_authentication: true) } let_it_be(:subgroup_without_2fa) { create(:group, parent: group, require_two_factor_authentication: false) } diff --git a/spec/workers/group_destroy_worker_spec.rb b/spec/workers/group_destroy_worker_spec.rb index fba4573718a..1bb2959f980 100644 --- a/spec/workers/group_destroy_worker_spec.rb +++ b/spec/workers/group_destroy_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe GroupDestroyWorker, feature_category: :subgroups do +RSpec.describe GroupDestroyWorker, feature_category: :groups_and_projects do let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project, namespace: group) } let_it_be(:user) { create(:user) } diff --git a/spec/workers/member_invitation_reminder_emails_worker_spec.rb b/spec/workers/member_invitation_reminder_emails_worker_spec.rb index 4c6295285ea..0a58939c0f5 100644 --- a/spec/workers/member_invitation_reminder_emails_worker_spec.rb +++ b/spec/workers/member_invitation_reminder_emails_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MemberInvitationReminderEmailsWorker, feature_category: :subgroups do +RSpec.describe MemberInvitationReminderEmailsWorker, feature_category: :groups_and_projects do describe '#perform' do subject { described_class.new.perform } diff --git a/spec/workers/packages/debian/process_changes_worker_spec.rb b/spec/workers/packages/debian/process_changes_worker_spec.rb index ddd608e768c..435ca33b223 100644 --- a/spec/workers/packages/debian/process_changes_worker_spec.rb +++ b/spec/workers/packages/debian/process_changes_worker_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Packages::Debian::ProcessChangesWorker, type: :worker, feature_ca create(:debian_project_distribution, :with_file, codename: FFaker::Lorem.word, suite: 'unstable') end - let(:incoming) { create(:debian_incoming, project: distribution.project) } + let(:incoming) { create(:debian_incoming, project: distribution.project, with_changes_file: true) } let(:package_file) { incoming.package_files.with_file_name('sample_1.2.3~alpha2_amd64.changes').first } let(:worker) { described_class.new } diff --git a/spec/workers/packages/debian/process_package_file_worker_spec.rb b/spec/workers/packages/debian/process_package_file_worker_spec.rb index 6010f4eac27..1ef3119ecd3 100644 --- a/spec/workers/packages/debian/process_package_file_worker_spec.rb +++ b/spec/workers/packages/debian/process_package_file_worker_spec.rb @@ -3,119 +3,147 @@ require 'spec_helper' RSpec.describe Packages::Debian::ProcessPackageFileWorker, type: :worker, feature_category: :package_registry do - let_it_be_with_reload(:distribution) { create(:debian_project_distribution, :with_file) } - let_it_be_with_reload(:package) do - create(:debian_package, :processing, project: distribution.project, published_in: nil) + shared_examples 'returns early without error' do + it 'returns early without error' do + expect(Gitlab::ErrorTracking).not_to receive(:log_exception) + expect(::Packages::Debian::ProcessPackageFileService).not_to receive(:new) + + subject + end end - let(:distribution_name) { distribution.codename } - let(:debian_file_metadatum) { package_file.debian_file_metadatum } - let(:worker) { described_class.new } + let_it_be_with_reload(:distribution) { create(:debian_project_distribution, :with_file) } + let_it_be_with_reload(:incoming) { create(:debian_incoming, project: distribution.project) } + let_it_be_with_reload(:temp_with_changes) { create(:debian_temporary_with_changes, project: distribution.project) } + let_it_be_with_reload(:temp_with_files) { create(:debian_temporary_with_files, project: distribution.project) } describe '#perform' do + let(:package) { temp_with_files } + let(:package_file) { package.package_files.with_file_name('libsample0_1.2.3~alpha2_amd64.deb').first } + let(:debian_file_metadatum) { package_file.debian_file_metadatum } + let(:worker) { described_class.new } + let(:package_file_id) { package_file.id } + let(:distribution_name) { distribution.codename } + let(:component_name) { 'main' } subject { worker.perform(package_file_id, distribution_name, component_name) } - shared_examples 'returns early without error' do - it 'returns early without error' do - expect(Gitlab::ErrorTracking).not_to receive(:log_exception) - expect(::Packages::Debian::ProcessPackageFileService).not_to receive(:new) + context 'with non existing package file' do + let(:package_file_id) { non_existing_record_id } - subject - end + it_behaves_like 'returns early without error' end - using RSpec::Parameterized::TableSyntax + context 'with nil package file id' do + let(:package_file_id) { nil } - where(:case_name, :expected_file_type, :file_name, :component_name) do - 'with a deb' | 'deb' | 'libsample0_1.2.3~alpha2_amd64.deb' | 'main' - 'with an udeb' | 'udeb' | 'sample-udeb_1.2.3~alpha2_amd64.udeb' | 'contrib' - 'with a ddeb' | 'ddeb' | 'sample-ddeb_1.2.3~alpha2_amd64.ddeb' | 'main' + it_behaves_like 'returns early without error' end - with_them do - context 'with Debian package file' do - let(:package_file) { package.package_files.with_file_name(file_name).first } - - context 'with mocked service' do - it 'calls ProcessPackageFileService' do - expect(Gitlab::ErrorTracking).not_to receive(:log_exception) - expect_next_instance_of(::Packages::Debian::ProcessPackageFileService) do |service| - expect(service).to receive(:execute) - .with(no_args) - end - - subject - end - end + context 'with already processed package file' do + let_it_be(:package_file) { create(:debian_package_file) } - context 'when the service raises an error' do - let(:package_file) { package.package_files.with_file_name('sample_1.2.3~alpha2.tar.xz').first } - - it 'marks the package as errored', :aggregate_failures do - expect(Gitlab::ErrorTracking).to receive(:log_exception).with( - instance_of(ArgumentError), - package_file_id: package_file_id, - distribution_name: distribution_name, - component_name: component_name - ) - expect { subject } - .to not_change(Packages::Package, :count) - .and not_change { Packages::PackageFile.count } - .and not_change { package.package_files.count } - .and change { package_file.reload.status }.to('error') - .and change { package.reload.status }.from('processing').to('error') - end - end + it_behaves_like 'returns early without error' + end - it_behaves_like 'an idempotent worker' do - let(:job_args) { [package_file.id, distribution_name, component_name] } - - it 'sets the Debian file type as deb', :aggregate_failures do - expect(::Packages::Debian::GenerateDistributionWorker) - .to receive(:perform_async).with(:project, distribution.id) - expect(Gitlab::ErrorTracking).not_to receive(:log_exception) - - # Using subject inside this block will process the job multiple times - expect { subject } - .to not_change(Packages::Package, :count) - .and not_change(Packages::PackageFile, :count) - .and change { Packages::Debian::Publication.count }.by(1) - .and not_change(package.package_files, :count) - .and change { package.reload.name }.to('sample') - .and change { package.version }.to('1.2.3~alpha2') - .and change { package.status }.from('processing').to('default') - .and change { package.debian_publication }.from(nil) - .and change { debian_file_metadatum.reload.file_type }.from('unknown').to(expected_file_type) - .and change { debian_file_metadatum.component }.from(nil).to(component_name) - end + context 'with mocked service' do + it 'calls ProcessPackageFileService' do + expect(Gitlab::ErrorTracking).not_to receive(:log_exception) + expect_next_instance_of(::Packages::Debian::ProcessPackageFileService) do |service| + expect(service).to receive(:execute) + .with(no_args) end + + subject end end - context 'with already processed package file' do - let_it_be(:package_file) { create(:debian_package_file) } - - let(:component_name) { 'main' } - - it_behaves_like 'returns early without error' + context 'when the service raises an error' do + let(:package_file) { package.package_files.with_file_name('sample_1.2.3~alpha2.tar.xz').first } + + it 'marks the package as errored', :aggregate_failures do + expect(Gitlab::ErrorTracking).to receive(:log_exception).with( + instance_of(ArgumentError), + package_file_id: package_file_id, + distribution_name: distribution_name, + component_name: component_name + ) + expect { subject } + .to not_change(Packages::Package, :count) + .and not_change { Packages::PackageFile.count } + .and not_change { package.package_files.count } + .and change { package_file.reload.status }.to('error') + .and change { package.reload.status }.from('processing').to('error') + end end - context 'with a deb' do - let(:package_file) { package.package_files.with_file_name('libsample0_1.2.3~alpha2_amd64.deb').first } - let(:component_name) { 'main' } + context 'with a Debian changes file' do + let(:package) { temp_with_changes } + let(:package_file) { package.package_files.first } + let(:distribution_name) { nil } + let(:component_name) { nil } - context 'with non existing package file' do - let(:package_file_id) { non_existing_record_id } + before do + distribution.update! suite: 'unstable' + end - it_behaves_like 'returns early without error' + it_behaves_like 'an idempotent worker' do + let(:job_args) { [package_file.id, distribution_name, component_name] } + + it 'sets the Debian file type to changes', :aggregate_failures do + expect(::Packages::Debian::GenerateDistributionWorker) + .to receive(:perform_async).with(:project, distribution.id) + expect(Gitlab::ErrorTracking).not_to receive(:log_exception) + + # Using subject inside this block will process the job multiple times + expect { subject } + .to not_change(Packages::Package, :count) + .and not_change(Packages::PackageFile, :count) + .and change { Packages::Debian::Publication.count }.by(1) + .and change { package.package_files.count }.from(1).to(8) + .and change { package.reload.name }.to('sample') + .and change { package.version }.to('1.2.3~alpha2') + .and change { package.status }.from('processing').to('default') + .and change { package.debian_publication }.from(nil) + .and change { debian_file_metadatum.reload.file_type }.from('unknown').to('changes') + .and not_change { debian_file_metadatum.component } + end end + end + + using RSpec::Parameterized::TableSyntax - context 'with nil package file id' do - let(:package_file_id) { nil } + where(:case_name, :expected_file_type, :file_name, :component_name) do + 'with a deb' | 'deb' | 'libsample0_1.2.3~alpha2_amd64.deb' | 'main' + 'with an udeb' | 'udeb' | 'sample-udeb_1.2.3~alpha2_amd64.udeb' | 'contrib' + 'with a ddeb' | 'ddeb' | 'sample-ddeb_1.2.3~alpha2_amd64.ddeb' | 'main' + end - it_behaves_like 'returns early without error' + with_them do + let(:package_file) { package.package_files.with_file_name(file_name).first } + + it_behaves_like 'an idempotent worker' do + let(:job_args) { [package_file.id, distribution_name, component_name] } + + it 'sets the correct Debian file type', :aggregate_failures do + expect(::Packages::Debian::GenerateDistributionWorker) + .to receive(:perform_async).with(:project, distribution.id) + expect(Gitlab::ErrorTracking).not_to receive(:log_exception) + + # Using subject inside this block will process the job multiple times + expect { subject } + .to not_change(Packages::Package, :count) + .and not_change(Packages::PackageFile, :count) + .and change { Packages::Debian::Publication.count }.by(1) + .and not_change(package.package_files, :count) + .and change { package.reload.name }.to('sample') + .and change { package.version }.to('1.2.3~alpha2') + .and change { package.status }.from('processing').to('default') + .and change { package.debian_publication }.from(nil) + .and change { debian_file_metadatum.reload.file_type }.from('unknown').to(expected_file_type) + .and change { debian_file_metadatum.component }.from(nil).to(component_name) + end end end end diff --git a/spec/workers/projects/finalize_project_statistics_refresh_worker_spec.rb b/spec/workers/projects/finalize_project_statistics_refresh_worker_spec.rb index 1379b6785eb..da2d35e97d8 100644 --- a/spec/workers/projects/finalize_project_statistics_refresh_worker_spec.rb +++ b/spec/workers/projects/finalize_project_statistics_refresh_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::FinalizeProjectStatisticsRefreshWorker, feature_category: :projects do +RSpec.describe Projects::FinalizeProjectStatisticsRefreshWorker, feature_category: :groups_and_projects do let_it_be(:record) { create(:project_build_artifacts_size_refresh, :finalizing) } describe '#perform' do diff --git a/spec/workers/projects/record_target_platforms_worker_spec.rb b/spec/workers/projects/record_target_platforms_worker_spec.rb index 0e106fe32f9..ecb6aab7349 100644 --- a/spec/workers/projects/record_target_platforms_worker_spec.rb +++ b/spec/workers/projects/record_target_platforms_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::RecordTargetPlatformsWorker, feature_category: :projects do +RSpec.describe Projects::RecordTargetPlatformsWorker, feature_category: :groups_and_projects do include ExclusiveLeaseHelpers let_it_be(:swift) { create(:programming_language, name: 'Swift') } |