2016-03-27 09:17:49 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ProjectCacheWorker do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
subject { described_class.new }
|
|
|
|
|
2016-10-25 10:01:24 -04:00
|
|
|
describe '.perform_async' do
|
|
|
|
it 'schedules the job when no lease exists' do
|
|
|
|
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:exists?).
|
|
|
|
and_return(false)
|
|
|
|
|
|
|
|
expect_any_instance_of(described_class).to receive(:perform)
|
|
|
|
|
|
|
|
described_class.perform_async(project.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not schedule the job when a lease exists' do
|
|
|
|
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:exists?).
|
|
|
|
and_return(true)
|
|
|
|
|
|
|
|
expect_any_instance_of(described_class).not_to receive(:perform)
|
|
|
|
|
|
|
|
described_class.perform_async(project.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-27 09:17:49 -04:00
|
|
|
describe '#perform' do
|
2016-10-20 06:59:39 -04:00
|
|
|
context 'when an exclusive lease can be obtained' do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:try_obtain_lease_for).with(project.id).
|
|
|
|
and_return(true)
|
|
|
|
end
|
2016-03-27 09:17:49 -04:00
|
|
|
|
2016-10-20 06:59:39 -04:00
|
|
|
it 'updates project cache data' do
|
|
|
|
expect_any_instance_of(Repository).to receive(:size)
|
|
|
|
expect_any_instance_of(Repository).to receive(:commit_count)
|
2016-03-27 09:17:49 -04:00
|
|
|
|
2016-10-20 06:59:39 -04:00
|
|
|
expect_any_instance_of(Project).to receive(:update_repository_size)
|
|
|
|
expect_any_instance_of(Project).to receive(:update_commit_count)
|
|
|
|
|
|
|
|
subject.perform(project.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'handles missing repository data' do
|
|
|
|
expect_any_instance_of(Repository).to receive(:exists?).and_return(false)
|
|
|
|
expect_any_instance_of(Repository).not_to receive(:size)
|
|
|
|
|
|
|
|
subject.perform(project.id)
|
|
|
|
end
|
2016-03-27 09:17:49 -04:00
|
|
|
end
|
|
|
|
|
2016-10-20 06:59:39 -04:00
|
|
|
context 'when an exclusive lease can not be obtained' do
|
|
|
|
it 'does nothing' do
|
|
|
|
allow(subject).to receive(:try_obtain_lease_for).with(project.id).
|
|
|
|
and_return(false)
|
|
|
|
|
|
|
|
expect(subject).not_to receive(:update_caches)
|
2016-03-27 09:17:49 -04:00
|
|
|
|
2016-10-20 06:59:39 -04:00
|
|
|
subject.perform(project.id)
|
|
|
|
end
|
2016-03-27 09:17:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|