diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
commit | 9297025d0b7ddf095eb618dfaaab2ff8f2018d8b (patch) | |
tree | 865198c01d1824a9b098127baa3ab980c9cd2c06 /spec/workers/packages/nuget/cleanup_stale_symbols_worker_spec.rb | |
parent | 6372471f43ee03c05a7c1f8b0c6ac6b8a7431dbe (diff) |
Add latest changes from gitlab-org/gitlab@16-7-stable-eev16.7.0-rc42
Diffstat (limited to 'spec/workers/packages/nuget/cleanup_stale_symbols_worker_spec.rb')
-rw-r--r-- | spec/workers/packages/nuget/cleanup_stale_symbols_worker_spec.rb | 77 |
1 files changed, 77 insertions, 0 deletions
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 |