diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-10 21:18:16 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-10 21:18:16 +0300 |
commit | e0277d5393d958865fdec470176ac5874edded06 (patch) | |
tree | f867094e393909ef822e354b1c72997ec5102f6f /spec/workers | |
parent | 74d9798736a89f07e047698e5e32964829bf8859 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/container_registry/migration/observer_worker_spec.rb | 57 | ||||
-rw-r--r-- | spec/workers/projects/git_garbage_collect_worker_spec.rb | 15 |
2 files changed, 72 insertions, 0 deletions
diff --git a/spec/workers/container_registry/migration/observer_worker_spec.rb b/spec/workers/container_registry/migration/observer_worker_spec.rb new file mode 100644 index 00000000000..fec6640d7ec --- /dev/null +++ b/spec/workers/container_registry/migration/observer_worker_spec.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ContainerRegistry::Migration::ObserverWorker, :aggregate_failures do + let(:worker) { described_class.new } + + describe '#perform' do + subject { worker.perform } + + context 'when the migration feature flag is disabled' do + before do + stub_feature_flags(container_registry_migration_phase2_enabled: false) + end + + it 'does nothing' do + expect(worker).not_to receive(:log_extra_metadata_on_done) + + subject + end + end + + context 'when the migration is enabled' do + before do + create_list(:container_repository, 3) + create(:container_repository, :pre_importing) + create(:container_repository, :pre_import_done) + create_list(:container_repository, 2, :importing) + create(:container_repository, :import_aborted) + # batch_count is not allowed within a transaction but + # all rspec tests run inside of a transaction. + # This mocks the false positive. + allow(ActiveRecord::Base.connection).to receive(:transaction_open?).and_return(false) # rubocop:disable Database/MultipleDatabases + end + + it 'logs all the counts' do + expect(worker).to receive(:log_extra_metadata_on_done).with(:default_count, 3) + expect(worker).to receive(:log_extra_metadata_on_done).with(:pre_importing_count, 1) + expect(worker).to receive(:log_extra_metadata_on_done).with(:pre_import_done_count, 1) + expect(worker).to receive(:log_extra_metadata_on_done).with(:importing_count, 2) + expect(worker).to receive(:log_extra_metadata_on_done).with(:import_done_count, 0) + expect(worker).to receive(:log_extra_metadata_on_done).with(:import_aborted_count, 1) + expect(worker).to receive(:log_extra_metadata_on_done).with(:import_skipped_count, 0) + + subject + end + + context 'with load balancing enabled', :db_load_balancing do + it 'uses 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 diff --git a/spec/workers/projects/git_garbage_collect_worker_spec.rb b/spec/workers/projects/git_garbage_collect_worker_spec.rb index 7b54d7df4b2..ae567107443 100644 --- a/spec/workers/projects/git_garbage_collect_worker_spec.rb +++ b/spec/workers/projects/git_garbage_collect_worker_spec.rb @@ -32,6 +32,21 @@ RSpec.describe Projects::GitGarbageCollectWorker do subject.perform(*params) end + + context 'when deduplication service runs into a GRPC internal error' do + before do + allow_next_instance_of(::Projects::GitDeduplicationService) do |instance| + expect(instance).to receive(:execute).and_raise(GRPC::Internal) + end + end + + it_behaves_like 'can collect git garbage' do + let(:resource) { project } + let(:statistics_service_klass) { Projects::UpdateStatisticsService } + let(:statistics_keys) { [:repository_size, :lfs_objects_size] } + let(:expected_default_lease) { "projects:#{resource.id}" } + end + end end context 'LFS object garbage collection' do |