Commit 59c728de authored by Imre Farkas's avatar Imre Farkas

Merge branch 'add_design_to_git_transfer_in_progress' into 'master'

Add design repository check to Project#git_transfer_in_progress?

See merge request gitlab-org/gitlab!48304
parents 3549441a 9a1a0467
...@@ -64,6 +64,8 @@ class Project < ApplicationRecord ...@@ -64,6 +64,8 @@ class Project < ApplicationRecord
SORTING_PREFERENCE_FIELD = :projects_sort SORTING_PREFERENCE_FIELD = :projects_sort
MAX_BUILD_TIMEOUT = 1.month MAX_BUILD_TIMEOUT = 1.month
GL_REPOSITORY_TYPES = [Gitlab::GlRepository::PROJECT, Gitlab::GlRepository::WIKI, Gitlab::GlRepository::DESIGN].freeze
cache_markdown_field :description, pipeline: :description cache_markdown_field :description, pipeline: :description
default_value_for :packages_enabled, true default_value_for :packages_enabled, true
...@@ -2275,7 +2277,9 @@ class Project < ApplicationRecord ...@@ -2275,7 +2277,9 @@ class Project < ApplicationRecord
end end
def git_transfer_in_progress? def git_transfer_in_progress?
repo_reference_count > 0 || wiki_reference_count > 0 GL_REPOSITORY_TYPES.any? do |type|
reference_counter(type: type).value > 0
end
end end
def storage_version=(value) def storage_version=(value)
...@@ -2608,14 +2612,6 @@ class Project < ApplicationRecord ...@@ -2608,14 +2612,6 @@ class Project < ApplicationRecord
end end
end end
def repo_reference_count
reference_counter.value
end
def wiki_reference_count
reference_counter(type: Gitlab::GlRepository::WIKI).value
end
def check_repository_absence! def check_repository_absence!
return if skip_disk_validation return if skip_disk_validation
......
---
title: Consider design repositories when determining if there is a git transfer in
progress
merge_request: 48304
author:
type: fixed
...@@ -4293,29 +4293,33 @@ RSpec.describe Project, factory_default: :keep do ...@@ -4293,29 +4293,33 @@ RSpec.describe Project, factory_default: :keep do
end end
describe '#git_transfer_in_progress?' do describe '#git_transfer_in_progress?' do
using RSpec::Parameterized::TableSyntax
let(:project) { build(:project) } let(:project) { build(:project) }
subject { project.git_transfer_in_progress? } subject { project.git_transfer_in_progress? }
it 'returns false when repo_reference_count and wiki_reference_count are 0' do where(:project_reference_counter, :wiki_reference_counter, :design_reference_counter, :result) do
allow(project).to receive(:repo_reference_count) { 0 } 0 | 0 | 0 | false
allow(project).to receive(:wiki_reference_count) { 0 } 2 | 0 | 0 | true
0 | 2 | 0 | true
expect(subject).to be_falsey 0 | 0 | 2 | true
end
it 'returns true when repo_reference_count is > 0' do
allow(project).to receive(:repo_reference_count) { 2 }
allow(project).to receive(:wiki_reference_count) { 0 }
expect(subject).to be_truthy
end end
it 'returns true when wiki_reference_count is > 0' do with_them do
allow(project).to receive(:repo_reference_count) { 0 } before do
allow(project).to receive(:wiki_reference_count) { 2 } allow(project).to receive(:reference_counter).with(type: Gitlab::GlRepository::PROJECT) do
double(:project_reference_counter, value: project_reference_counter)
end
allow(project).to receive(:reference_counter).with(type: Gitlab::GlRepository::WIKI) do
double(:wiki_reference_counter, value: wiki_reference_counter)
end
allow(project).to receive(:reference_counter).with(type: Gitlab::GlRepository::DESIGN) do
double(:design_reference_counter, value: design_reference_counter)
end
end
expect(subject).to be_truthy specify { expect(subject).to be result }
end end
end end
......
...@@ -28,7 +28,7 @@ RSpec.describe Projects::HashedStorage::MigrateRepositoryService do ...@@ -28,7 +28,7 @@ RSpec.describe Projects::HashedStorage::MigrateRepositoryService do
end end
it 'fails when a git operation is in progress' do it 'fails when a git operation is in progress' do
allow(project).to receive(:repo_reference_count) { 1 } allow(project).to receive(:git_transfer_in_progress?) { true }
expect { service.execute }.to raise_error(Projects::HashedStorage::RepositoryInUseError) expect { service.execute }.to raise_error(Projects::HashedStorage::RepositoryInUseError)
end end
......
...@@ -28,7 +28,7 @@ RSpec.describe Projects::HashedStorage::RollbackRepositoryService, :clean_gitlab ...@@ -28,7 +28,7 @@ RSpec.describe Projects::HashedStorage::RollbackRepositoryService, :clean_gitlab
end end
it 'fails when a git operation is in progress' do it 'fails when a git operation is in progress' do
allow(project).to receive(:repo_reference_count) { 1 } allow(project).to receive(:git_transfer_in_progress?) { true }
expect { service.execute }.to raise_error(Projects::HashedStorage::RepositoryInUseError) expect { service.execute }.to raise_error(Projects::HashedStorage::RepositoryInUseError)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment