summaryrefslogtreecommitdiff
path: root/spec/requests/api/circuit_breakers_spec.rb
blob: 3b858c40fd64e840145e59ba15cd77034458919d (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
54
55
56
57
require 'spec_helper'

describe API::CircuitBreakers do
  let(:user) { create(:user) }
  let(:admin) { create(:admin) }

  describe 'GET circuit_breakers/repository_storage' do
    it 'returns a 401 for anonymous users' do
      get api('/circuit_breakers/repository_storage')

      expect(response).to have_gitlab_http_status(401)
    end

    it 'returns a 403 for users' do
      get api('/circuit_breakers/repository_storage', user)

      expect(response).to have_gitlab_http_status(403)
    end

    it 'returns an Array of storages' do
      expect(Gitlab::Git::Storage::Health).to receive(:for_all_storages) do
        [Gitlab::Git::Storage::Health.new('broken', [{ name: 'prefix:broken:web01', failure_count: 4 }])]
      end

      get api('/circuit_breakers/repository_storage', admin)

      expect(response).to have_gitlab_http_status(200)
      expect(json_response).to be_kind_of(Array)
      expect(json_response.first['storage_name']).to eq('broken')
      expect(json_response.first['failing_on_hosts']).to eq(['web01'])
      expect(json_response.first['total_failures']).to eq(4)
    end

    describe 'GET circuit_breakers/repository_storage/failing' do
      it 'returns an array of failing storages' do
        expect(Gitlab::Git::Storage::Health).to receive(:for_failing_storages) do
          [Gitlab::Git::Storage::Health.new('broken', [{ name: 'prefix:broken:web01', failure_count: 4 }])]
        end

        get api('/circuit_breakers/repository_storage/failing', admin)

        expect(response).to have_gitlab_http_status(200)
        expect(json_response).to be_kind_of(Array)
      end
    end
  end

  describe 'DELETE circuit_breakers/repository_storage' do
    it 'clears all circuit_breakers' do
      expect(Gitlab::Git::Storage::CircuitBreaker).to receive(:reset_all!)

      delete api('/circuit_breakers/repository_storage', admin)

      expect(response).to have_gitlab_http_status(204)
    end
  end
end