Commit 2c05c857 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'improve-housekeeping-spec' into 'master'

Backport changes for Housekeeping Specs

See merge request gitlab-org/gitlab-ce!18595
parents 7e5bdb13 57129140
...@@ -2,7 +2,7 @@ require 'spec_helper' ...@@ -2,7 +2,7 @@ require 'spec_helper'
describe Projects::HousekeepingService do describe Projects::HousekeepingService do
subject { described_class.new(project) } subject { described_class.new(project) }
let(:project) { create(:project, :repository) } set(:project) { create(:project, :repository) }
before do before do
project.reset_pushes_since_gc project.reset_pushes_since_gc
...@@ -16,12 +16,12 @@ describe Projects::HousekeepingService do ...@@ -16,12 +16,12 @@ describe Projects::HousekeepingService do
it 'enqueues a sidekiq job' do it 'enqueues a sidekiq job' do
expect(subject).to receive(:try_obtain_lease).and_return(:the_uuid) expect(subject).to receive(:try_obtain_lease).and_return(:the_uuid)
expect(subject).to receive(:lease_key).and_return(:the_lease_key) expect(subject).to receive(:lease_key).and_return(:the_lease_key)
expect(subject).to receive(:task).and_return(:the_task) expect(subject).to receive(:task).and_return(:incremental_repack)
expect(GitGarbageCollectWorker).to receive(:perform_async).with(project.id, :the_task, :the_lease_key, :the_uuid) expect(GitGarbageCollectWorker).to receive(:perform_async).with(project.id, :incremental_repack, :the_lease_key, :the_uuid).and_call_original
subject.execute Sidekiq::Testing.fake! do
expect { subject.execute }.to change(GitGarbageCollectWorker.jobs, :size).by(1)
expect(project.reload.pushes_since_gc).to eq(0) end
end end
it 'yields the block if given' do it 'yields the block if given' do
...@@ -30,6 +30,16 @@ describe Projects::HousekeepingService do ...@@ -30,6 +30,16 @@ describe Projects::HousekeepingService do
end.to yield_with_no_args end.to yield_with_no_args
end end
it 'resets counter after execution' do
expect(subject).to receive(:try_obtain_lease).and_return(:the_uuid)
allow(subject).to receive(:gc_period).and_return(1)
project.increment_pushes_since_gc
Sidekiq::Testing.inline! do
expect { subject.execute }.to change { project.pushes_since_gc }.to(0)
end
end
context 'when no lease can be obtained' do context 'when no lease can be obtained' do
before do before do
expect(subject).to receive(:try_obtain_lease).and_return(false) expect(subject).to receive(:try_obtain_lease).and_return(false)
...@@ -54,27 +64,8 @@ describe Projects::HousekeepingService do ...@@ -54,27 +64,8 @@ describe Projects::HousekeepingService do
end.not_to yield_with_no_args end.not_to yield_with_no_args
end end
end end
end
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
describe '#increment!' do
it 'increments the pushes_since_gc counter' do
expect do
subject.increment!
end.to change { project.pushes_since_gc }.from(0).to(1)
end
end
context 'task type' do
it 'goes through all three housekeeping tasks, executing only the highest task when there is overlap' do it 'goes through all three housekeeping tasks, executing only the highest task when there is overlap' do
allow(subject).to receive(:try_obtain_lease).and_return(:the_uuid) allow(subject).to receive(:try_obtain_lease).and_return(:the_uuid)
allow(subject).to receive(:lease_key).and_return(:the_lease_key) allow(subject).to receive(:lease_key).and_return(:the_lease_key)
...@@ -96,4 +87,23 @@ describe Projects::HousekeepingService do ...@@ -96,4 +87,23 @@ describe Projects::HousekeepingService do
expect(project.pushes_since_gc).to eq(1) expect(project.pushes_since_gc).to eq(1)
end end
end
end
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
describe '#increment!' do
it 'increments the pushes_since_gc counter' do
expect { subject.increment! }.to change { project.pushes_since_gc }.by(1)
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