diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-29 21:12:41 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-29 21:12:41 +0300 |
commit | 2d239d2421eea466ff5c51aebdbf05a18ded20c7 (patch) | |
tree | 85f9c0b6063158ff01112b9945f57bc35bd47970 /spec/workers | |
parent | 762918f04a2ee8f4f7fac3d551c14af8dd30f17c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers')
3 files changed, 100 insertions, 0 deletions
diff --git a/spec/workers/every_sidekiq_worker_spec.rb b/spec/workers/every_sidekiq_worker_spec.rb index 82f9762bd4e..2db8cebe58c 100644 --- a/spec/workers/every_sidekiq_worker_spec.rb +++ b/spec/workers/every_sidekiq_worker_spec.rb @@ -393,6 +393,7 @@ RSpec.describe 'Every Sidekiq worker', feature_category: :shared do 'Packages::MarkPackageFilesForDestructionWorker' => 3, 'Packages::Maven::Metadata::SyncWorker' => 3, 'Packages::Npm::CleanupStaleMetadataCacheWorker' => 0, + 'Packages::Nuget::CleanupStaleSymbolsWorker' => 0, 'Packages::Nuget::ExtractionWorker' => 3, 'Packages::Rubygems::ExtractionWorker' => 3, 'PagesDomainSslRenewalWorker' => 3, diff --git a/spec/workers/packages/cleanup_package_registry_worker_spec.rb b/spec/workers/packages/cleanup_package_registry_worker_spec.rb index f2787a92fbf..0d2f9629327 100644 --- a/spec/workers/packages/cleanup_package_registry_worker_spec.rb +++ b/spec/workers/packages/cleanup_package_registry_worker_spec.rb @@ -80,6 +80,28 @@ RSpec.describe Packages::CleanupPackageRegistryWorker, feature_category: :packag end end + context 'with nuget symbols pending destruction' do + let_it_be(:nuget_symbol) { create(:nuget_symbol, :stale) } + + include_examples 'an idempotent worker' do + it 'queues the cleanup job' do + expect(Packages::Nuget::CleanupStaleSymbolsWorker).to receive(:perform_with_capacity) + + perform + end + end + end + + context 'with no nuget symbols pending destruction' do + include_examples 'an idempotent worker' do + it 'does not queue the cleanup job' do + expect(Packages::Nuget::CleanupStaleSymbolsWorker).not_to receive(:perform_with_capacity) + + perform + end + end + end + describe 'counts logging' do let_it_be(:processing_package_file) { create(:package_file, status: :processing) } diff --git a/spec/workers/packages/nuget/cleanup_stale_symbols_worker_spec.rb b/spec/workers/packages/nuget/cleanup_stale_symbols_worker_spec.rb new file mode 100644 index 00000000000..41afe64a808 --- /dev/null +++ b/spec/workers/packages/nuget/cleanup_stale_symbols_worker_spec.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Packages::Nuget::CleanupStaleSymbolsWorker, type: :worker, feature_category: :package_registry do + let(:worker) { described_class.new } + + describe '#perform_work' do + subject(:perform_work) { worker.perform_work } + + context 'with no work to do' do + it { is_expected.to be_nil } + end + + context 'with work to do' do + let_it_be(:symbol_1) { create(:nuget_symbol) } + let_it_be(:symbol_2) { create(:nuget_symbol, :stale) } + + it 'deletes the stale symbol', :aggregate_failures do + expect(worker).to receive(:log_extra_metadata_on_done).with(:nuget_symbol_id, symbol_2.id) + expect(Packages::Nuget::Symbol).to receive(:next_pending_destruction).with(order_by: nil).and_call_original + expect { perform_work }.to change { Packages::Nuget::Symbol.count }.by(-1) + expect { symbol_2.reload }.to raise_error(ActiveRecord::RecordNotFound) + end + end + + context 'with a stale symbol' do + let_it_be(:symbol) { create(:nuget_symbol, :stale) } + + context 'with an error during deletion' do + before do + allow_next_found_instance_of(Packages::Nuget::Symbol) do |instance| + allow(instance).to receive(:destroy!).and_raise(StandardError) + end + end + + it 'handles the error' do + expect(Gitlab::ErrorTracking).to receive(:log_exception).with( + instance_of(StandardError), class: described_class.name + ) + + expect { perform_work }.to change { Packages::Nuget::Symbol.error.count }.by(1) + expect(symbol.reload).to be_error + end + end + + context 'when trying to destroy a destroyed record' do + before do + allow_next_found_instance_of(Packages::Nuget::Symbol) do |instance| + destroy_method = instance.method(:destroy!) + + allow(instance).to receive(:destroy!) do + destroy_method.call + + raise StandardError + end + end + end + + it 'handles the error' do + expect(Gitlab::ErrorTracking).to receive(:log_exception) + .with(instance_of(StandardError), class: described_class.name) + expect { perform_work }.not_to change { Packages::Nuget::Symbol.count } + expect(symbol.reload).to be_error + end + end + end + end + + describe '#max_running_jobs' do + let(:capacity) { described_class::MAX_CAPACITY } + + subject { worker.max_running_jobs } + + it { is_expected.to eq(capacity) } + end +end |