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/container_registry | |
parent | 74d9798736a89f07e047698e5e32964829bf8859 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers/container_registry')
-rw-r--r-- | spec/workers/container_registry/migration/observer_worker_spec.rb | 57 |
1 files changed, 57 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 |