Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-26 03:08:24 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-26 03:08:24 +0300
commiteb90b0642d7949bfa03c8e9b5f39d211934fb0b5 (patch)
tree270a1a9cf9d6c491fbee55c7f3e793e04e12560a /spec/workers/container_registry
parente0096a0ef1fa770c16c4f7f0ecea618433d7b052 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers/container_registry')
-rw-r--r--spec/workers/container_registry/migration/guard_worker_spec.rb78
1 files changed, 73 insertions, 5 deletions
diff --git a/spec/workers/container_registry/migration/guard_worker_spec.rb b/spec/workers/container_registry/migration/guard_worker_spec.rb
index ee479099df3..30f5957c7c7 100644
--- a/spec/workers/container_registry/migration/guard_worker_spec.rb
+++ b/spec/workers/container_registry/migration/guard_worker_spec.rb
@@ -134,16 +134,15 @@ RSpec.describe ContainerRegistry::Migration::GuardWorker, :aggregate_failures do
end
context 'with pre_importing stale migrations' do
- let(:ongoing_migration) { create(:container_repository, :pre_importing) }
- let(:stale_migration) { create(:container_repository, :pre_importing, migration_pre_import_started_at: 11.minutes.ago) }
+ let_it_be(:ongoing_migration) { create(:container_repository, :pre_importing) }
+ let_it_be(:stale_migration) { create(:container_repository, :pre_importing, migration_pre_import_started_at: 11.minutes.ago) }
+
let(:import_status) { 'test' }
before do
allow_next_instance_of(ContainerRegistry::GitlabApiClient) do |client|
allow(client).to receive(:import_status).and_return(import_status)
end
-
- stub_application_setting(container_registry_pre_import_timeout: 10.minutes.to_i)
end
it 'will abort the migration' do
@@ -163,7 +162,76 @@ RSpec.describe ContainerRegistry::Migration::GuardWorker, :aggregate_failures do
context 'the client returns pre_import_in_progress' do
let(:import_status) { 'pre_import_in_progress' }
- it_behaves_like 'handling long running migrations', timeout: :pre_import_timeout
+ shared_examples 'not aborting the stale migration' do
+ it 'will not abort the migration' do
+ expect(worker).to receive(:log_extra_metadata_on_done).with(:stale_migrations_count, 1)
+ expect(worker).to receive(:log_extra_metadata_on_done).with(:aborted_stale_migrations_count, 0)
+
+ expect { subject }
+ .to not_change(pre_importing_migrations, :count)
+ .and not_change(pre_import_done_migrations, :count)
+ .and not_change(importing_migrations, :count)
+ .and not_change(import_done_migrations, :count)
+ .and not_change(import_aborted_migrations, :count)
+ .and not_change { stale_migration.reload.migration_state }
+ .and not_change { ongoing_migration.migration_state }
+ end
+ end
+
+ context 'not long running' do
+ before do
+ stub_application_setting(container_registry_pre_import_timeout: 12.minutes.to_i)
+ end
+
+ it_behaves_like 'not aborting the stale migration'
+ end
+
+ context 'long running' do
+ before do
+ stub_application_setting(container_registry_pre_import_timeout: 9.minutes.to_i)
+ end
+
+ context 'with registry_migration_guard_dynamic_pre_import_timeout enabled' do
+ before do
+ stub_application_setting(container_registry_pre_import_tags_rate: 1)
+ end
+
+ context 'below the dynamic threshold' do
+ before do
+ allow_next_found_instance_of(ContainerRepository) do |repository|
+ allow(repository).to receive(:tags_count).and_return(11.minutes.to_i + 100)
+ end
+ end
+
+ it_behaves_like 'not aborting the stale migration'
+ end
+
+ context 'above the dynamic threshold' do
+ let(:tags) do
+ Array.new(11.minutes.to_i - 100) { |i| "tag#{i}" }
+ end
+
+ before do
+ # We can't allow_next_found_instance_of because the shared example
+ # 'handling long running migrations' is already using that.
+ # Instead, here we're going to stub the ContainerRegistry::Client instance.
+ allow_next_instance_of(ContainerRegistry::Client) do |client|
+ allow(client).to receive(:repository_tags).and_return({ 'tags' => tags })
+ end
+ end
+
+ it_behaves_like 'handling long running migrations', timeout: :pre_import_timeout
+ end
+ end
+
+ context 'with registry_migration_guard_dynamic_pre_import_timeout disabled' do
+ before do
+ stub_feature_flags(registry_migration_guard_dynamic_pre_import_timeout: false)
+ end
+
+ it_behaves_like 'handling long running migrations', timeout: :pre_import_timeout
+ end
+ end
end
end