Commit decf6fb0 authored by Corinna Wiesner's avatar Corinna Wiesner Committed by Tyler Amos

Avoid using the current's project excess twice

The calculation for the exceeded size for a project used the project's
excess size twice as it was also included in the total repository size
excess. This is corrected by calculating the project's excess size and
substracting it from the total repository size.
parent 0177b2c0
......@@ -19,7 +19,7 @@ module EE
def exceeded_size(change_size = 0)
exceeded_size = super
exceeded_size -= remaining_additional_purchased_storage if additional_repo_storage_available?
exceeded_size
[exceeded_size, 0].max
end
private
......@@ -38,8 +38,16 @@ module EE
namespace&.additional_purchased_storage_size&.megabytes.to_i
end
def current_project_excess
[current_size - limit, 0].max
end
def total_excess_without_current_project
total_repository_size_excess - current_project_excess
end
def remaining_additional_purchased_storage
additional_purchased_storage - total_repository_size_excess
additional_purchased_storage - total_excess_without_current_project
end
end
end
......
......@@ -136,39 +136,51 @@ RSpec.describe Gitlab::RepositorySizeChecker do
stub_feature_flags(namespace_storage_limit: false)
end
context 'when current size + total repository size excess are below or equal to the limit + additional purchased storage' do
let(:current_size) { 50 }
context 'with additional purchased storage' do
let(:total_repository_size_excess) { 10 }
let(:additional_purchased_storage) { 10 }
it 'returns zero' do
expect(subject.exceeded_size).to eq(0)
context 'when current size + total repository size excess are below or equal to the project\'s limit (no need for additional purchase storage)' do
let(:current_size) { 50 }
it 'returns zero' do
expect(subject.exceeded_size).to eq(0)
end
end
end
context 'when current size + total repository size excess are over the limit + additional purchased storage' do
let(:current_size) { 51 }
let(:total_repository_size_excess) { 10 }
let(:additional_purchased_storage) { 10 }
context 'when there is remaining storage (current size + excess for other projects need to use additional purchased storage but not all of it)' do
let(:current_size) { 51 }
it 'returns 1' do
expect(subject.exceeded_size).to eq(1.megabytes)
it 'returns 0' do
expect(subject.exceeded_size).to eq(0)
end
end
end
context 'when change size will be over the limit' do
let(:current_size) { 50 }
context 'when there storage is exceeded (current size + excess for other projects exceed additional purchased storage' do
let(:total_repository_size_excess) { 15 }
let(:current_size) { 61 }
it 'returns 1' do
expect(subject.exceeded_size(1.megabytes)).to eq(1.megabytes)
it 'returns 1' do
expect(subject.exceeded_size).to eq(5.megabytes)
end
end
end
context 'when change size will not be over the limit' do
let(:current_size) { 49 }
context 'without additional purchased storage' do
context 'when change size will be over the limit' do
let(:current_size) { 50 }
it 'returns 1' do
expect(subject.exceeded_size(1.megabytes)).to eq(1.megabytes)
end
end
context 'when change size will not be over the limit' do
let(:current_size) { 49 }
it 'returns zero' do
expect(subject.exceeded_size(1.megabytes)).to eq(0)
it 'returns zero' do
expect(subject.exceeded_size(1.megabytes)).to eq(0)
end
end
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