2021-11-18 22:05:49 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe DependencyProxy::ImageTtlGroupPolicyWorker do
|
|
|
|
let(:worker) { described_class.new }
|
|
|
|
|
|
|
|
describe '#perform' do
|
|
|
|
let_it_be(:policy) { create(:image_ttl_group_policy) }
|
|
|
|
let_it_be(:group) { policy.group }
|
|
|
|
|
|
|
|
subject { worker.perform }
|
|
|
|
|
|
|
|
context 'when there are images to expire' do
|
2021-12-11 22:18:48 +05:30
|
|
|
let_it_be_with_reload(:old_blob) { create(:dependency_proxy_blob, group: group, read_at: 1.year.ago) }
|
|
|
|
let_it_be_with_reload(:old_manifest) { create(:dependency_proxy_manifest, group: group, read_at: 1.year.ago) }
|
2021-11-18 22:05:49 +05:30
|
|
|
let_it_be_with_reload(:new_blob) { create(:dependency_proxy_blob, group: group) }
|
|
|
|
let_it_be_with_reload(:new_manifest) { create(:dependency_proxy_manifest, group: group) }
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it 'updates the old images to pending_destruction' do
|
2021-11-18 22:05:49 +05:30
|
|
|
expect { subject }
|
2022-03-02 08:16:31 +05:30
|
|
|
.to change { old_blob.reload.status }.from('default').to('pending_destruction')
|
|
|
|
.and change { old_manifest.reload.status }.from('default').to('pending_destruction')
|
2021-11-18 22:05:49 +05:30
|
|
|
.and not_change { new_blob.reload.status }
|
|
|
|
.and not_change { new_manifest.reload.status }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'counts logging' do
|
2022-03-02 08:16:31 +05:30
|
|
|
let_it_be(:expired_blob) { create(:dependency_proxy_blob, :pending_destruction, group: group) }
|
|
|
|
let_it_be(:expired_blob2) { create(:dependency_proxy_blob, :pending_destruction, group: group) }
|
|
|
|
let_it_be(:expired_manifest) { create(:dependency_proxy_manifest, :pending_destruction, group: group) }
|
2021-11-18 22:05:49 +05:30
|
|
|
let_it_be(:processing_blob) { create(:dependency_proxy_blob, status: :processing, group: group) }
|
|
|
|
let_it_be(:processing_manifest) { create(:dependency_proxy_manifest, status: :processing, group: group) }
|
|
|
|
let_it_be(:error_blob) { create(:dependency_proxy_blob, status: :error, group: group) }
|
|
|
|
let_it_be(:error_manifest) { create(:dependency_proxy_manifest, status: :error, group: group) }
|
|
|
|
|
|
|
|
it 'logs all the counts', :aggregate_failures do
|
|
|
|
expect(worker).to receive(:log_extra_metadata_on_done).with(:expired_dependency_proxy_blob_count, 2)
|
|
|
|
expect(worker).to receive(:log_extra_metadata_on_done).with(:expired_dependency_proxy_manifest_count, 1)
|
|
|
|
expect(worker).to receive(:log_extra_metadata_on_done).with(:processing_dependency_proxy_blob_count, 1)
|
|
|
|
expect(worker).to receive(:log_extra_metadata_on_done).with(:processing_dependency_proxy_manifest_count, 1)
|
|
|
|
expect(worker).to receive(:log_extra_metadata_on_done).with(:error_dependency_proxy_blob_count, 1)
|
|
|
|
expect(worker).to receive(:log_extra_metadata_on_done).with(:error_dependency_proxy_manifest_count, 1)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with load balancing enabled', :db_load_balancing do
|
|
|
|
it 'reads the counts from the replica' do
|
|
|
|
expect(Gitlab::Database::LoadBalancing::Session.current).to receive(:use_replicas_for_read_queries).and_call_original
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|