2016-03-27 09:17:49 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ProjectCacheWorker do
|
|
|
|
let(:project) { create(:project) }
|
2016-11-18 08:04:18 -05:00
|
|
|
let(:worker) { described_class.new }
|
2016-03-27 09:17:49 -04:00
|
|
|
|
2016-11-18 08:04:18 -05:00
|
|
|
describe '#perform' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain).
|
|
|
|
and_return(true)
|
|
|
|
end
|
2016-10-25 10:01:24 -04:00
|
|
|
|
2016-11-18 08:04:18 -05:00
|
|
|
context 'with a non-existing project' do
|
|
|
|
it 'does nothing' do
|
|
|
|
expect(worker).not_to receive(:update_repository_size)
|
2016-10-25 10:01:24 -04:00
|
|
|
|
2016-11-18 08:04:18 -05:00
|
|
|
worker.perform(-1)
|
|
|
|
end
|
2016-10-25 10:01:24 -04:00
|
|
|
end
|
|
|
|
|
2016-11-18 08:04:18 -05:00
|
|
|
context 'with an existing project without a repository' do
|
|
|
|
it 'does nothing' do
|
|
|
|
allow_any_instance_of(Repository).to receive(:exists?).and_return(false)
|
2016-10-25 10:01:24 -04:00
|
|
|
|
2016-11-18 08:04:18 -05:00
|
|
|
expect(worker).not_to receive(:update_repository_size)
|
2016-10-25 10:01:24 -04:00
|
|
|
|
2016-11-18 08:04:18 -05:00
|
|
|
worker.perform(project.id)
|
|
|
|
end
|
2016-10-25 10:01:24 -04:00
|
|
|
end
|
|
|
|
|
2016-11-18 08:04:18 -05:00
|
|
|
context 'with an existing project' do
|
|
|
|
it 'updates the repository size' do
|
|
|
|
expect(worker).to receive(:update_repository_size).and_call_original
|
2016-03-27 09:17:49 -04:00
|
|
|
|
2016-11-18 08:04:18 -05:00
|
|
|
worker.perform(project.id)
|
|
|
|
end
|
2016-03-27 09:17:49 -04:00
|
|
|
|
2016-11-18 08:04:18 -05:00
|
|
|
it 'updates the commit count' do
|
|
|
|
expect_any_instance_of(Project).to receive(:update_commit_count).
|
|
|
|
and_call_original
|
2016-10-20 06:59:39 -04:00
|
|
|
|
2016-11-18 08:04:18 -05:00
|
|
|
worker.perform(project.id)
|
2016-10-20 06:59:39 -04:00
|
|
|
end
|
|
|
|
|
2016-11-18 08:04:18 -05:00
|
|
|
it 'refreshes the method caches' do
|
|
|
|
expect_any_instance_of(Repository).to receive(:refresh_method_caches).
|
|
|
|
with(%i(readme)).
|
|
|
|
and_call_original
|
2016-10-20 06:59:39 -04:00
|
|
|
|
2016-11-18 08:04:18 -05:00
|
|
|
worker.perform(project.id, %i(readme))
|
2016-10-20 06:59:39 -04:00
|
|
|
end
|
2016-03-27 09:17:49 -04:00
|
|
|
end
|
2016-11-18 08:04:18 -05:00
|
|
|
end
|
2016-03-27 09:17:49 -04:00
|
|
|
|
2016-11-18 08:04:18 -05:00
|
|
|
describe '#update_repository_size' do
|
|
|
|
context 'when a lease could not be obtained' do
|
|
|
|
it 'does not update the repository size' do
|
|
|
|
allow(worker).to receive(:try_obtain_lease_for).
|
|
|
|
with(project.id, :update_repository_size).
|
2016-10-20 06:59:39 -04:00
|
|
|
and_return(false)
|
|
|
|
|
2016-11-18 08:04:18 -05:00
|
|
|
expect(project).not_to receive(:update_repository_size)
|
|
|
|
|
|
|
|
worker.update_repository_size(project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a lease could be obtained' do
|
|
|
|
it 'updates the repository size' do
|
|
|
|
allow(worker).to receive(:try_obtain_lease_for).
|
|
|
|
with(project.id, :update_repository_size).
|
|
|
|
and_return(true)
|
|
|
|
|
|
|
|
expect(project).to receive(:update_repository_size).and_call_original
|
2016-03-27 09:17:49 -04:00
|
|
|
|
2016-11-18 08:04:18 -05:00
|
|
|
worker.update_repository_size(project)
|
2016-10-20 06:59:39 -04:00
|
|
|
end
|
2016-03-27 09:17:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|