2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2016-11-22 11:58:10 -05:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe ProjectStatistics do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create :project }
|
2016-11-22 11:58:10 -05:00
|
|
|
let(:statistics) { project.statistics }
|
|
|
|
|
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:project) }
|
|
|
|
it { is_expected.to belong_to(:namespace) }
|
|
|
|
end
|
|
|
|
|
2019-05-12 17:10:46 -04:00
|
|
|
describe 'scopes' do
|
|
|
|
describe '.for_project_ids' do
|
|
|
|
it 'returns only requested projects' do
|
|
|
|
stats = create_list(:project_statistics, 3)
|
|
|
|
project_ids = stats[0..1].map { |s| s.project_id }
|
|
|
|
expected_ids = stats[0..1].map { |s| s.id }
|
|
|
|
|
|
|
|
requested_stats = described_class.for_project_ids(project_ids).pluck(:id)
|
|
|
|
|
|
|
|
expect(requested_stats).to eq(expected_ids)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-22 11:58:10 -05:00
|
|
|
describe 'statistics columns' do
|
|
|
|
it "support values up to 8 exabytes" do
|
|
|
|
statistics.update!(
|
|
|
|
commit_count: 8.exabytes - 1,
|
|
|
|
repository_size: 2.exabytes,
|
2019-02-13 17:38:11 -05:00
|
|
|
wiki_size: 1.exabytes,
|
2016-11-22 11:58:10 -05:00
|
|
|
lfs_objects_size: 2.exabytes,
|
2020-08-24 08:10:17 -04:00
|
|
|
build_artifacts_size: 1.exabyte,
|
|
|
|
snippets_size: 1.exabyte,
|
2020-11-13 19:09:32 -05:00
|
|
|
pipeline_artifacts_size: 512.petabytes - 1,
|
2022-04-25 08:09:50 -04:00
|
|
|
uploads_size: 500.petabytes,
|
|
|
|
container_registry_size: 12.petabytes
|
2016-11-22 11:58:10 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
statistics.reload
|
|
|
|
|
|
|
|
expect(statistics.commit_count).to eq(8.exabytes - 1)
|
|
|
|
expect(statistics.repository_size).to eq(2.exabytes)
|
2019-02-13 17:38:11 -05:00
|
|
|
expect(statistics.wiki_size).to eq(1.exabytes)
|
2016-11-22 11:58:10 -05:00
|
|
|
expect(statistics.lfs_objects_size).to eq(2.exabytes)
|
2020-08-24 08:10:17 -04:00
|
|
|
expect(statistics.build_artifacts_size).to eq(1.exabyte)
|
2016-11-22 11:58:10 -05:00
|
|
|
expect(statistics.storage_size).to eq(8.exabytes - 1)
|
2020-06-26 11:08:45 -04:00
|
|
|
expect(statistics.snippets_size).to eq(1.exabyte)
|
2020-11-13 19:09:32 -05:00
|
|
|
expect(statistics.pipeline_artifacts_size).to eq(512.petabytes - 1)
|
2022-04-25 08:09:50 -04:00
|
|
|
expect(statistics.uploads_size).to eq(500.petabytes)
|
|
|
|
expect(statistics.container_registry_size).to eq(12.petabytes)
|
2016-11-22 11:58:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#total_repository_size' do
|
|
|
|
it "sums repository and LFS object size" do
|
|
|
|
statistics.repository_size = 2
|
2019-02-13 17:38:11 -05:00
|
|
|
statistics.wiki_size = 6
|
2016-11-22 11:58:10 -05:00
|
|
|
statistics.lfs_objects_size = 3
|
|
|
|
statistics.build_artifacts_size = 4
|
2020-06-26 11:08:45 -04:00
|
|
|
statistics.snippets_size = 5
|
2020-11-13 19:09:32 -05:00
|
|
|
statistics.uploads_size = 3
|
2022-04-25 08:09:50 -04:00
|
|
|
statistics.container_registry_size = 8
|
2016-11-22 11:58:10 -05:00
|
|
|
|
|
|
|
expect(statistics.total_repository_size).to eq 5
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-13 17:38:11 -05:00
|
|
|
describe '#wiki_size' do
|
2020-06-26 11:08:45 -04:00
|
|
|
it 'is initialized with not null value' do
|
|
|
|
expect(statistics.attributes['wiki_size']).to be_zero
|
|
|
|
expect(statistics.wiki_size).to be_zero
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'coerces any nil value to 0' do
|
|
|
|
statistics.update!(wiki_size: nil)
|
|
|
|
|
|
|
|
expect(statistics.attributes['wiki_size']).to be_nil
|
2019-02-13 17:38:11 -05:00
|
|
|
expect(statistics.wiki_size).to eq 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-26 11:08:45 -04:00
|
|
|
describe '#snippets_size' do
|
|
|
|
it 'is initialized with not null value' do
|
|
|
|
expect(statistics.attributes['snippets_size']).to be_zero
|
|
|
|
expect(statistics.snippets_size).to be_zero
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'coerces any nil value to 0' do
|
|
|
|
statistics.update!(snippets_size: nil)
|
|
|
|
|
|
|
|
expect(statistics.attributes['snippets_size']).to be_nil
|
|
|
|
expect(statistics.snippets_size).to eq 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-22 11:58:10 -05:00
|
|
|
describe '#refresh!' do
|
|
|
|
before do
|
|
|
|
allow(statistics).to receive(:update_commit_count)
|
|
|
|
allow(statistics).to receive(:update_repository_size)
|
2019-02-13 17:38:11 -05:00
|
|
|
allow(statistics).to receive(:update_wiki_size)
|
2016-11-22 11:58:10 -05:00
|
|
|
allow(statistics).to receive(:update_lfs_objects_size)
|
2020-06-26 11:08:45 -04:00
|
|
|
allow(statistics).to receive(:update_snippets_size)
|
2016-11-22 11:58:10 -05:00
|
|
|
allow(statistics).to receive(:update_storage_size)
|
2020-11-13 19:09:32 -05:00
|
|
|
allow(statistics).to receive(:update_uploads_size)
|
2022-04-25 08:09:50 -04:00
|
|
|
allow(statistics).to receive(:update_container_registry_size)
|
2016-11-22 11:58:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "without arguments" do
|
|
|
|
before do
|
|
|
|
statistics.refresh!
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sums all counters" do
|
|
|
|
expect(statistics).to have_received(:update_commit_count)
|
|
|
|
expect(statistics).to have_received(:update_repository_size)
|
2019-02-13 17:38:11 -05:00
|
|
|
expect(statistics).to have_received(:update_wiki_size)
|
2016-11-22 11:58:10 -05:00
|
|
|
expect(statistics).to have_received(:update_lfs_objects_size)
|
2020-06-26 11:08:45 -04:00
|
|
|
expect(statistics).to have_received(:update_snippets_size)
|
2020-11-13 19:09:32 -05:00
|
|
|
expect(statistics).to have_received(:update_uploads_size)
|
2022-04-25 08:09:50 -04:00
|
|
|
expect(statistics).to have_received(:update_container_registry_size)
|
2016-11-22 11:58:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when passing an only: argument" do
|
|
|
|
before do
|
|
|
|
statistics.refresh! only: [:lfs_objects_size]
|
|
|
|
end
|
|
|
|
|
|
|
|
it "only updates the given columns" do
|
|
|
|
expect(statistics).to have_received(:update_lfs_objects_size)
|
|
|
|
expect(statistics).not_to have_received(:update_commit_count)
|
|
|
|
expect(statistics).not_to have_received(:update_repository_size)
|
2019-02-13 17:38:11 -05:00
|
|
|
expect(statistics).not_to have_received(:update_wiki_size)
|
2020-06-26 11:08:45 -04:00
|
|
|
expect(statistics).not_to have_received(:update_snippets_size)
|
2020-11-13 19:09:32 -05:00
|
|
|
expect(statistics).not_to have_received(:update_uploads_size)
|
2022-04-25 08:09:50 -04:00
|
|
|
expect(statistics).not_to have_received(:update_container_registry_size)
|
2016-11-22 11:58:10 -05:00
|
|
|
end
|
|
|
|
end
|
2019-05-29 10:09:41 -04:00
|
|
|
|
|
|
|
context 'without repositories' do
|
|
|
|
it 'does not crash' do
|
|
|
|
expect(project.repository.exists?).to be_falsey
|
|
|
|
expect(project.wiki.repository.exists?).to be_falsey
|
|
|
|
|
|
|
|
statistics.refresh!
|
|
|
|
|
|
|
|
expect(statistics).to have_received(:update_commit_count)
|
|
|
|
expect(statistics).to have_received(:update_repository_size)
|
|
|
|
expect(statistics).to have_received(:update_wiki_size)
|
2020-06-26 11:08:45 -04:00
|
|
|
expect(statistics).to have_received(:update_snippets_size)
|
2020-11-13 19:09:32 -05:00
|
|
|
expect(statistics).to have_received(:update_uploads_size)
|
2022-04-25 08:09:50 -04:00
|
|
|
expect(statistics).to have_received(:update_container_registry_size)
|
2019-05-29 10:09:41 -04:00
|
|
|
expect(statistics.repository_size).to eq(0)
|
|
|
|
expect(statistics.commit_count).to eq(0)
|
|
|
|
expect(statistics.wiki_size).to eq(0)
|
2020-06-26 11:08:45 -04:00
|
|
|
expect(statistics.snippets_size).to eq(0)
|
2020-11-13 19:09:32 -05:00
|
|
|
expect(statistics.uploads_size).to eq(0)
|
2022-04-25 08:09:50 -04:00
|
|
|
expect(statistics.container_registry_size).to eq(0)
|
2019-05-29 10:09:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with deleted repositories' do
|
|
|
|
let(:project) { create(:project, :repository, :wiki_repo) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Gitlab::GitalyClient::StorageSettings.allow_disk_access do
|
|
|
|
FileUtils.rm_rf(project.repository.path)
|
|
|
|
FileUtils.rm_rf(project.wiki.repository.path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not crash' do
|
|
|
|
statistics.refresh!
|
|
|
|
|
|
|
|
expect(statistics).to have_received(:update_commit_count)
|
|
|
|
expect(statistics).to have_received(:update_repository_size)
|
|
|
|
expect(statistics).to have_received(:update_wiki_size)
|
2020-06-26 11:08:45 -04:00
|
|
|
expect(statistics).to have_received(:update_snippets_size)
|
2020-11-13 19:09:32 -05:00
|
|
|
expect(statistics).to have_received(:update_uploads_size)
|
2022-04-25 08:09:50 -04:00
|
|
|
expect(statistics).to have_received(:update_container_registry_size)
|
2019-05-29 10:09:41 -04:00
|
|
|
expect(statistics.repository_size).to eq(0)
|
|
|
|
expect(statistics.commit_count).to eq(0)
|
|
|
|
expect(statistics.wiki_size).to eq(0)
|
2020-06-26 11:08:45 -04:00
|
|
|
expect(statistics.snippets_size).to eq(0)
|
2020-11-13 19:09:32 -05:00
|
|
|
expect(statistics.uploads_size).to eq(0)
|
2022-04-25 08:09:50 -04:00
|
|
|
expect(statistics.container_registry_size).to eq(0)
|
2019-05-29 10:09:41 -04:00
|
|
|
end
|
|
|
|
end
|
2019-07-08 11:06:05 -04:00
|
|
|
|
|
|
|
context 'when the column is namespace relatable' do
|
|
|
|
let(:namespace) { create(:group) }
|
|
|
|
let(:project) { create(:project, namespace: namespace) }
|
|
|
|
|
2019-08-01 16:14:21 -04:00
|
|
|
context 'when arguments are passed' do
|
2019-07-08 11:06:05 -04:00
|
|
|
it 'schedules the aggregation worker' do
|
|
|
|
expect(Namespaces::ScheduleAggregationWorker)
|
|
|
|
.to receive(:perform_async)
|
|
|
|
|
|
|
|
statistics.refresh!(only: [:lfs_objects_size])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no argument is passed' do
|
|
|
|
it 'schedules the aggregation worker' do
|
|
|
|
expect(Namespaces::ScheduleAggregationWorker)
|
|
|
|
.to receive(:perform_async)
|
|
|
|
|
|
|
|
statistics.refresh!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the column is not namespace relatable' do
|
|
|
|
it 'does not schedules an aggregation worker' do
|
|
|
|
expect(Namespaces::ScheduleAggregationWorker)
|
|
|
|
.not_to receive(:perform_async)
|
|
|
|
|
|
|
|
statistics.refresh!(only: [:commit_count])
|
|
|
|
end
|
|
|
|
end
|
2020-09-19 11:09:58 -04:00
|
|
|
|
|
|
|
context 'when the database is read-only' do
|
|
|
|
it 'does nothing' do
|
2021-08-02 05:10:09 -04:00
|
|
|
allow(Gitlab::Database).to receive(:read_only?) { true }
|
2020-09-19 11:09:58 -04:00
|
|
|
|
|
|
|
expect(statistics).not_to receive(:update_commit_count)
|
|
|
|
expect(statistics).not_to receive(:update_repository_size)
|
|
|
|
expect(statistics).not_to receive(:update_wiki_size)
|
|
|
|
expect(statistics).not_to receive(:update_lfs_objects_size)
|
|
|
|
expect(statistics).not_to receive(:update_snippets_size)
|
2020-11-13 19:09:32 -05:00
|
|
|
expect(statistics).not_to receive(:update_uploads_size)
|
2022-04-25 08:09:50 -04:00
|
|
|
expect(statistics).not_to receive(:update_container_registry_size)
|
2020-09-19 11:09:58 -04:00
|
|
|
expect(statistics).not_to receive(:save!)
|
|
|
|
expect(Namespaces::ScheduleAggregationWorker)
|
|
|
|
.not_to receive(:perform_async)
|
|
|
|
|
|
|
|
statistics.refresh!
|
|
|
|
end
|
|
|
|
end
|
2016-11-22 11:58:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#update_commit_count' do
|
|
|
|
before do
|
|
|
|
allow(project.repository).to receive(:commit_count).and_return(23)
|
|
|
|
statistics.update_commit_count
|
|
|
|
end
|
|
|
|
|
|
|
|
it "stores the number of commits in the repository" do
|
|
|
|
expect(statistics.commit_count).to eq 23
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#update_repository_size' do
|
|
|
|
before do
|
2017-01-17 13:29:31 -05:00
|
|
|
allow(project.repository).to receive(:size).and_return(12)
|
2016-11-22 11:58:10 -05:00
|
|
|
statistics.update_repository_size
|
|
|
|
end
|
|
|
|
|
|
|
|
it "stores the size of the repository" do
|
|
|
|
expect(statistics.repository_size).to eq 12.megabytes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-13 17:38:11 -05:00
|
|
|
describe '#update_wiki_size' do
|
|
|
|
before do
|
|
|
|
allow(project.wiki.repository).to receive(:size).and_return(34)
|
|
|
|
statistics.update_wiki_size
|
|
|
|
end
|
|
|
|
|
|
|
|
it "stores the size of the wiki" do
|
|
|
|
expect(statistics.wiki_size).to eq 34.megabytes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-26 11:08:45 -04:00
|
|
|
describe '#update_snippets_size' do
|
|
|
|
before do
|
|
|
|
create_list(:project_snippet, 2, project: project)
|
|
|
|
SnippetStatistics.update_all(repository_size: 10)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'stores the size of snippets' do
|
|
|
|
# Snippet not associated with the project
|
|
|
|
snippet = create(:project_snippet)
|
|
|
|
snippet.statistics.update!(repository_size: 40)
|
|
|
|
|
|
|
|
statistics.update_snippets_size
|
|
|
|
|
|
|
|
expect(statistics.update_snippets_size).to eq 20
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not all snippets has statistics' do
|
|
|
|
it 'stores the size of snippets with statistics' do
|
|
|
|
SnippetStatistics.last.delete
|
|
|
|
|
|
|
|
statistics.update_snippets_size
|
|
|
|
|
|
|
|
expect(statistics.update_snippets_size).to eq 10
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-22 11:58:10 -05:00
|
|
|
describe '#update_lfs_objects_size' do
|
|
|
|
let!(:lfs_object1) { create(:lfs_object, size: 23.megabytes) }
|
|
|
|
let!(:lfs_object2) { create(:lfs_object, size: 34.megabytes) }
|
2021-09-22 20:12:17 -04:00
|
|
|
let!(:lfs_object3) { create(:lfs_object, size: 34.megabytes) }
|
2016-11-22 11:58:10 -05:00
|
|
|
let!(:lfs_objects_project1) { create(:lfs_objects_project, project: project, lfs_object: lfs_object1) }
|
|
|
|
let!(:lfs_objects_project2) { create(:lfs_objects_project, project: project, lfs_object: lfs_object2) }
|
2021-09-22 20:12:17 -04:00
|
|
|
let!(:lfs_objects_project3) { create(:lfs_objects_project, project: project, lfs_object: lfs_object3) }
|
2016-11-22 11:58:10 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
statistics.update_lfs_objects_size
|
|
|
|
end
|
|
|
|
|
|
|
|
it "stores the size of related LFS objects" do
|
2021-09-22 20:12:17 -04:00
|
|
|
expect(statistics.lfs_objects_size).to eq 91.megabytes
|
2016-11-22 11:58:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-13 19:09:32 -05:00
|
|
|
describe '#update_uploads_size' do
|
|
|
|
let!(:upload1) { create(:upload, model: project, size: 1.megabyte) }
|
|
|
|
let!(:upload2) { create(:upload, model: project, size: 2.megabytes) }
|
|
|
|
|
|
|
|
it 'stores the size of related uploaded files' do
|
|
|
|
expect(statistics.update_uploads_size).to eq(3.megabytes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-25 08:09:50 -04:00
|
|
|
describe '#update_container_registry_size' do
|
|
|
|
subject(:update_container_registry_size) { statistics.update_container_registry_size }
|
|
|
|
|
|
|
|
it 'stores the project container registry repositories size' do
|
|
|
|
allow(project).to receive(:container_repositories_size).and_return(10)
|
|
|
|
|
|
|
|
update_container_registry_size
|
|
|
|
|
|
|
|
expect(statistics.container_registry_size).to eq(10)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'handles nil values for the repositories size' do
|
|
|
|
allow(project).to receive(:container_repositories_size).and_return(nil)
|
|
|
|
|
|
|
|
update_container_registry_size
|
|
|
|
|
|
|
|
expect(statistics.container_registry_size).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with container_registry_project_statistics FF disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(container_registry_project_statistics: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not update the container_registry_size' do
|
|
|
|
expect(project).not_to receive(:container_repositories_size)
|
|
|
|
|
|
|
|
update_container_registry_size
|
|
|
|
|
|
|
|
expect(statistics.container_registry_size).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-22 11:58:10 -05:00
|
|
|
describe '#update_storage_size' do
|
|
|
|
it "sums all storage counters" do
|
|
|
|
statistics.update!(
|
|
|
|
repository_size: 2,
|
2019-02-13 17:38:11 -05:00
|
|
|
wiki_size: 4,
|
2020-06-26 11:08:45 -04:00
|
|
|
lfs_objects_size: 3,
|
2020-08-24 08:10:17 -04:00
|
|
|
snippets_size: 2,
|
2020-11-13 19:09:32 -05:00
|
|
|
pipeline_artifacts_size: 3,
|
2021-10-28 08:10:22 -04:00
|
|
|
build_artifacts_size: 3,
|
|
|
|
packages_size: 6,
|
2022-04-25 08:09:50 -04:00
|
|
|
uploads_size: 5,
|
|
|
|
container_registry_size: 10
|
2016-11-22 11:58:10 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
statistics.reload
|
|
|
|
|
2022-04-25 08:09:50 -04:00
|
|
|
expect(statistics.storage_size).to eq 38
|
2016-11-22 11:58:10 -05:00
|
|
|
end
|
2019-06-10 11:44:50 -04:00
|
|
|
|
|
|
|
it 'works during wiki_size backfill' do
|
|
|
|
statistics.update!(
|
|
|
|
repository_size: 2,
|
|
|
|
wiki_size: nil,
|
|
|
|
lfs_objects_size: 3
|
|
|
|
)
|
|
|
|
|
|
|
|
statistics.reload
|
|
|
|
|
|
|
|
expect(statistics.storage_size).to eq 5
|
|
|
|
end
|
2020-06-26 11:08:45 -04:00
|
|
|
|
|
|
|
context 'when nullable columns are nil' do
|
|
|
|
it 'does not raise any error' do
|
|
|
|
expect do
|
|
|
|
statistics.update!(
|
|
|
|
repository_size: 2,
|
|
|
|
wiki_size: nil,
|
|
|
|
lfs_objects_size: 3,
|
|
|
|
snippets_size: nil
|
|
|
|
)
|
|
|
|
end.not_to raise_error
|
|
|
|
|
|
|
|
expect(statistics.storage_size).to eq 5
|
|
|
|
end
|
|
|
|
end
|
2016-11-22 11:58:10 -05:00
|
|
|
end
|
2018-03-20 19:03:50 -04:00
|
|
|
|
|
|
|
describe '.increment_statistic' do
|
2019-05-02 12:04:15 -04:00
|
|
|
shared_examples 'a statistic that increases storage_size' do
|
|
|
|
it 'increases the statistic by that amount' do
|
2020-09-18 08:09:50 -04:00
|
|
|
expect { described_class.increment_statistic(project, stat, 13) }
|
2019-05-02 12:04:15 -04:00
|
|
|
.to change { statistics.reload.send(stat) || 0 }
|
|
|
|
.by(13)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'increases also storage size by that amount' do
|
2020-09-18 08:09:50 -04:00
|
|
|
expect { described_class.increment_statistic(project, stat, 20) }
|
2020-07-30 17:09:35 -04:00
|
|
|
.to change { statistics.reload.storage_size }
|
|
|
|
.by(20)
|
2019-05-02 12:04:15 -04:00
|
|
|
end
|
2018-03-20 19:03:50 -04:00
|
|
|
end
|
|
|
|
|
2020-09-18 08:09:50 -04:00
|
|
|
shared_examples 'a statistic that increases storage_size asynchronously' do
|
|
|
|
it 'stores the increment temporarily in Redis', :clean_gitlab_redis_shared_state do
|
|
|
|
described_class.increment_statistic(project, stat, 13)
|
|
|
|
|
|
|
|
Gitlab::Redis::SharedState.with do |redis|
|
|
|
|
increment = redis.get(statistics.counter_key(stat))
|
|
|
|
expect(increment.to_i).to eq(13)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'schedules a worker to update the statistic and storage_size async' do
|
|
|
|
expect(FlushCounterIncrementsWorker)
|
|
|
|
.to receive(:perform_in)
|
|
|
|
.with(CounterAttribute::WORKER_DELAY, described_class.name, statistics.id, stat)
|
|
|
|
|
|
|
|
expect(FlushCounterIncrementsWorker)
|
|
|
|
.to receive(:perform_in)
|
|
|
|
.with(CounterAttribute::WORKER_DELAY, described_class.name, statistics.id, :storage_size)
|
|
|
|
|
|
|
|
described_class.increment_statistic(project, stat, 20)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-02 12:04:15 -04:00
|
|
|
context 'when adjusting :build_artifacts_size' do
|
|
|
|
let(:stat) { :build_artifacts_size }
|
|
|
|
|
2020-09-18 08:09:50 -04:00
|
|
|
it_behaves_like 'a statistic that increases storage_size asynchronously'
|
2019-05-02 12:04:15 -04:00
|
|
|
end
|
|
|
|
|
2020-08-24 08:10:17 -04:00
|
|
|
context 'when adjusting :pipeline_artifacts_size' do
|
|
|
|
let(:stat) { :pipeline_artifacts_size }
|
|
|
|
|
|
|
|
it_behaves_like 'a statistic that increases storage_size'
|
|
|
|
end
|
|
|
|
|
2019-05-02 12:04:15 -04:00
|
|
|
context 'when adjusting :packages_size' do
|
|
|
|
let(:stat) { :packages_size }
|
|
|
|
|
|
|
|
it_behaves_like 'a statistic that increases storage_size'
|
2018-07-18 12:25:56 -04:00
|
|
|
end
|
|
|
|
|
2018-03-20 19:03:50 -04:00
|
|
|
context 'when the amount is 0' do
|
|
|
|
it 'does not execute a query' do
|
|
|
|
project
|
|
|
|
expect { described_class.increment_statistic(project.id, :build_artifacts_size, 0) }
|
|
|
|
.not_to exceed_query_limit(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when using an invalid column' do
|
|
|
|
it 'raises an error' do
|
|
|
|
expect { described_class.increment_statistic(project.id, :id, 13) }
|
|
|
|
.to raise_error(ArgumentError, "Cannot increment attribute: id")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-11-22 11:58:10 -05:00
|
|
|
end
|