gitlab-org--gitlab-foss/spec/services/projects/housekeeping_service_spec.rb

49 lines
1.4 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe Projects::HousekeepingService do
subject { Projects::HousekeepingService.new(project) }
let(:project) { create :project }
2016-03-14 17:46:38 +00:00
describe 'execute' do
before do
project.pushes_since_gc = 3
project.save!
end
it 'enqueues a sidekiq job' do
expect(subject).to receive(:try_obtain_lease).and_return(true)
2016-03-18 13:46:51 +00:00
expect(GitlabShellOneShotWorker).to receive(:perform_async).with(:gc, project.path_with_namespace)
2016-03-15 10:03:43 +00:00
subject.execute
expect(project.pushes_since_gc).to eq(0)
end
it 'does not enqueue a job when no lease can be obtained' do
expect(subject).to receive(:try_obtain_lease).and_return(false)
2016-03-18 13:46:51 +00:00
expect(GitlabShellOneShotWorker).not_to receive(:perform_async)
2016-03-15 10:03:43 +00:00
expect { subject.execute }.to raise_error(Projects::HousekeepingService::LeaseTaken)
expect(project.pushes_since_gc).to eq(0)
end
end
2016-03-14 17:46:38 +00:00
describe 'needed?' do
it 'when the count is low enough' do
expect(subject.needed?).to eq(false)
end
it 'when the count is high enough' do
allow(project).to receive(:pushes_since_gc).and_return(10)
expect(subject.needed?).to eq(true)
end
end
2016-03-14 15:49:24 +00:00
2016-03-14 17:46:38 +00:00
describe 'increment!' do
2016-03-14 15:49:24 +00:00
it 'increments the pushes_since_gc counter' do
expect(project.pushes_since_gc).to eq(0)
subject.increment!
expect(project.pushes_since_gc).to eq(1)
end
end
end