Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dispatch_worker_spec.rb « repository_check « workers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 829abc7d895f986b5e6b2451acb56e6bd6acad50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe RepositoryCheck::DispatchWorker do
  subject { described_class.new }

  it 'does nothing when repository checks are disabled' do
    stub_application_setting(repository_checks_enabled: false)

    expect(RepositoryCheck::BatchWorker).not_to receive(:perform_async)

    subject.perform
  end

  it 'does nothing if the exclusive lease is taken' do
    allow(subject).to receive(:try_obtain_lease).and_return(false)

    expect(RepositoryCheck::BatchWorker).not_to receive(:perform_async)

    subject.perform
  end

  it 'dispatches work to RepositoryCheck::BatchWorker' do
    expect(RepositoryCheck::BatchWorker).to receive(:perform_async).at_least(:once)

    subject.perform
  end

  context 'with unhealthy shard' do
    let(:default_shard_name) { 'default' }
    let(:unhealthy_shard_name) { 'unhealthy' }
    let(:default_shard) { Gitlab::HealthChecks::Result.new('gitaly_check', true, nil, shard: default_shard_name) }
    let(:unhealthy_shard) { Gitlab::HealthChecks::Result.new('gitaly_check', false, '14:Connect Failed', shard: unhealthy_shard_name) }

    before do
      allow(Gitlab::HealthChecks::GitalyCheck).to receive(:readiness).and_return([default_shard, unhealthy_shard])
    end

    it 'only triggers RepositoryCheck::BatchWorker for healthy shards' do
      expect(RepositoryCheck::BatchWorker).to receive(:perform_async).with('default')

      subject.perform
    end

    it 'logs unhealthy shards' do
      log_data = { message: "Excluding unhealthy shards", failed_checks: [{ labels: { shard: unhealthy_shard_name }, message: '14:Connect Failed', status: 'failed' }], class: described_class.name }
      expect(Gitlab::AppLogger).to receive(:error).with(a_hash_including(log_data))

      subject.perform
    end
  end
end