geo_backfill_worker_spec.rb 1.35 KB
Newer Older
1 2 3
require 'spec_helper'

describe Geo::GeoBackfillWorker, services: true do
4 5 6 7 8 9
  let!(:primary)   { create(:geo_node, :primary, host: 'primary-geo-node') }
  let!(:secondary) { create(:geo_node, :current) }
  let!(:projects)  { create_list(:empty_project, 2) }

  subject { described_class.new }

10
  describe '#perform' do
11 12 13 14
    before do
      allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { true }
    end

15 16
    it 'performs Geo::RepositoryBackfillService for each project' do
      expect(Geo::RepositoryBackfillService).to receive(:new).twice.and_return(spy)
17 18 19 20

      subject.perform
    end

21
    it 'does not perform Geo::RepositoryBackfillService when node is disabled' do
22
      allow_any_instance_of(GeoNode).to receive(:enabled?) { false }
23

24
      expect(Geo::RepositoryBackfillService).not_to receive(:new)
25 26 27 28

      subject.perform
    end

29
    it 'does not perform Geo::RepositoryBackfillService for projects that repository exists' do
30 31
      create_list(:project, 2)

32
      expect(Geo::RepositoryBackfillService).to receive(:new).twice.and_return(spy)
33 34 35 36

      subject.perform
    end

37
    it 'does not perform Geo::RepositoryBackfillService when can not obtain a lease' do
38 39
      allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { false }

40
      expect(Geo::RepositoryBackfillService).not_to receive(:new)
41 42 43

      subject.perform
    end
44 45
  end
end