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

server_spec.rb « health_checks « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 65d24acbf22338a6f636886a2f0ca56f587824a6 (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
58
59
60
61
62
63
64
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::HealthChecks::Server do
  context 'with running server thread' do
    subject(:server) { described_class.new(address: 'localhost', port: 8082) }

    before do
      # We need to send a request to localhost
      WebMock.allow_net_connect!

      server.start
    end

    after do
      webmock_enable!

      server.stop
    end

    shared_examples 'serves health check at' do |path|
      it 'responds with 200 OK' do
        response = Gitlab::HTTP.try_get("http://localhost:8082/#{path}", allow_local_requests: true)

        expect(response.code).to eq(200)
      end
    end

    describe '/readiness' do
      it_behaves_like 'serves health check at', 'readiness'
    end

    describe '/liveness' do
      it_behaves_like 'serves health check at', 'liveness'
    end

    describe 'other routes' do
      it 'serves 404' do
        response = Gitlab::HTTP.try_get("http://localhost:8082/other", allow_local_requests: true)

        expect(response.code).to eq(404)
      end
    end
  end

  context 'when server thread goes away' do
    before do
      expect_next_instance_of(::WEBrick::HTTPServer) do |webrick|
        allow(webrick).to receive(:start)
        expect(webrick).to receive(:listeners).and_call_original
      end
    end

    specify 'stop closes TCP socket' do
      server = described_class.new(address: 'localhost', port: 8082)
      server.start

      expect(server.thread).to receive(:alive?).and_return(false).at_least(:once)

      server.stop
    end
  end
end