diff options
-rw-r--r-- | lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config.rb | 9 | ||||
-rw-r--r-- | spec/migrations/backfill_store_project_full_path_in_repo_spec.rb | 18 |
2 files changed, 24 insertions, 3 deletions
diff --git a/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config.rb b/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config.rb index a3b5324cc1d..36eff3078aa 100644 --- a/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config.rb +++ b/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config.rb @@ -106,6 +106,10 @@ module Gitlab repository_service.delete_config([FULLPATH_CONFIG_KEY]) end + def cleanup_repository + repository_service.cleanup + end + def storage @storage ||= if hashed_storage? @@ -138,7 +142,10 @@ module Gitlab def perform(project_id, retry_count) project = Project.find(project_id) - migration_class.new.safe_perform_one(project, retry_count) if project + return unless project + + project.cleanup_repository + migration_class.new.safe_perform_one(project, retry_count) end end diff --git a/spec/migrations/backfill_store_project_full_path_in_repo_spec.rb b/spec/migrations/backfill_store_project_full_path_in_repo_spec.rb index ced6b09dfc0..aa5b82e0e43 100644 --- a/spec/migrations/backfill_store_project_full_path_in_repo_spec.rb +++ b/spec/migrations/backfill_store_project_full_path_in_repo_spec.rb @@ -20,6 +20,12 @@ describe BackfillStoreProjectFullPathInRepo, :migration do describe '#up' do shared_examples_for 'writes the full path to git config' do + let(:repository_service) { spy(:repository_service) } + + def stub_repository_service + allow(Gitlab::GitalyClient::RepositoryService).to receive(:new).and_return(repository_service) + end + it 'writes the git config' do expect_any_instance_of(Gitlab::GitalyClient::RepositoryService) .to receive(:set_config).with('gitlab.fullpath' => expected_path) @@ -28,15 +34,23 @@ describe BackfillStoreProjectFullPathInRepo, :migration do end it 'retries in case of failure' do - repository_service = spy(:repository_service) + stub_repository_service - allow(Gitlab::GitalyClient::RepositoryService).to receive(:new).and_return(repository_service) allow(repository_service).to receive(:set_config).and_raise(GRPC::BadStatus, 'Retry me') expect(repository_service).to receive(:set_config).exactly(3).times migration.up end + it 'cleans up repository in case of failure' do + stub_repository_service + + allow(repository_service).to receive(:set_config).and_raise(GRPC::BadStatus, 'Retry me') + expect(repository_service).to receive(:cleanup) + + migration.up + end + context 'legacy storage' do it 'finds the repository at the correct location' do Project.find(project.id).create_repository |