GitLab steht wegen Wartungsarbeiten am Montag, den 10. Mai, zwischen 17:00 und 19:00 Uhr nicht zur Verfügung.

housekeeping_service_spec.rb 1.37 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 }

Jacob Vosmaer's avatar
Jacob Vosmaer committed
7
  describe 'execute' do
8 9 10 11 12 13 14
    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)
Jacob Vosmaer's avatar
Jacob Vosmaer committed
15
      expect(GitlabShellOneShotWorker).to receive(:perform_async).with(:gc, project.path_with_namespace)
16

17
      subject.execute
18 19 20 21 22
      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)
Jacob Vosmaer's avatar
Jacob Vosmaer committed
23
      expect(GitlabShellOneShotWorker).not_to receive(:perform_async)
24

25 26
      expect { subject.execute }.to raise_error(Projects::HousekeepingService::LeaseTaken)
      expect(project.pushes_since_gc).to eq(0)
27 28 29
    end
  end

Jacob Vosmaer's avatar
Jacob Vosmaer committed
30
  describe 'needed?' do
31 32 33 34 35 36 37 38 39
    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
40

Jacob Vosmaer's avatar
Jacob Vosmaer committed
41
  describe 'increment!' do
Jacob Vosmaer's avatar
Jacob Vosmaer committed
42 43 44 45 46 47 48
    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