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
SORTING_PREFERENCE_FIELD = :projects_sort
MAX_BUILD_TIMEOUT = 1.month
GL_REPOSITORY_TYPES = [Gitlab::GlRepository::PROJECT, Gitlab::GlRepository::WIKI, Gitlab::GlRepository::DESIGN].freeze
cache_markdown_field :description, pipeline: :description
default_value_for :packages_enabled, true
......@@ -2275,7 +2277,9 @@ class Project < ApplicationRecord
end
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
def storage_version=(value)
......@@ -2608,14 +2612,6 @@ class Project < ApplicationRecord
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!
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
end
describe '#git_transfer_in_progress?' do
using RSpec::Parameterized::TableSyntax
let(:project) { build(:project) }
subject { project.git_transfer_in_progress? }
it 'returns false when repo_reference_count and wiki_reference_count are 0' do
allow(project).to receive(:repo_reference_count) { 0 }
allow(project).to receive(:wiki_reference_count) { 0 }
expect(subject).to be_falsey
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
where(:project_reference_counter, :wiki_reference_counter, :design_reference_counter, :result) do
0 | 0 | 0 | false
2 | 0 | 0 | true
0 | 2 | 0 | true
0 | 0 | 2 | true
end
it 'returns true when wiki_reference_count is > 0' do
allow(project).to receive(:repo_reference_count) { 0 }
allow(project).to receive(:wiki_reference_count) { 2 }
with_them do
before do
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
......
......@@ -28,7 +28,7 @@ RSpec.describe Projects::HashedStorage::MigrateRepositoryService do
end
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)
end
......
......@@ -28,7 +28,7 @@ RSpec.describe Projects::HashedStorage::RollbackRepositoryService, :clean_gitlab
end
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)
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