GitLab steht aufgrund eines wichtigen Updates heute, zwischen 18:00 und 19:00 Uhr, nicht zur Verfügung.

housekeeping_service_spec.rb 1.61 KB
Newer Older
1 2 3 4 5 6
require 'spec_helper'

describe Projects::HousekeepingService do
  subject { Projects::HousekeepingService.new(project) }
  let(:project) { create :project }

7 8 9 10
  before do
    project.reset_pushes_since_gc
  end

Yorick Peterse's avatar
Yorick Peterse committed
11 12 13
  after do
    project.reset_pushes_since_gc
  end
14

Yorick Peterse's avatar
Yorick Peterse committed
15
  describe '#execute' do
16 17
    it 'enqueues a sidekiq job' do
      expect(subject).to receive(:try_obtain_lease).and_return(true)
18
      expect(GitGarbageCollectWorker).to receive(:perform_async).with(project.id)
19

20
      subject.execute
21
      expect(project.reload.pushes_since_gc).to eq(0)
22 23
    end

24 25 26 27
    context 'when no lease can be obtained' do
      before(:each) do
        expect(subject).to receive(:try_obtain_lease).and_return(false)
      end
28

29 30 31 32 33 34 35 36 37
      it 'does not enqueue a job' do
        expect(GitGarbageCollectWorker).not_to receive(:perform_async)

        expect { subject.execute }.to raise_error(Projects::HousekeepingService::LeaseTaken)
      end

      it 'does not reset pushes_since_gc' do
        expect do
          expect { subject.execute }.to raise_error(Projects::HousekeepingService::LeaseTaken)
Yorick Peterse's avatar
Yorick Peterse committed
38
        end.not_to change { project.pushes_since_gc }
39
      end
40 41 42
    end
  end

Yorick Peterse's avatar
Yorick Peterse committed
43
  describe '#needed?' do
44 45 46 47 48 49 50 51 52
    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
Jacob Vosmaer's avatar
Jacob Vosmaer committed
53

Yorick Peterse's avatar
Yorick Peterse committed
54
  describe '#increment!' do
Jacob Vosmaer's avatar
Jacob Vosmaer committed
55
    it 'increments the pushes_since_gc counter' do
56 57 58 59
      expect do
        subject.increment!
      end.to change { project.pushes_since_gc }.from(0).to(1)
    end
Jacob Vosmaer's avatar
Jacob Vosmaer committed
60 61
  end
end