diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-16 18:06:17 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-16 18:06:17 +0300 |
commit | 00c78fb814d7ce00989ac04edd6cdaa3239da284 (patch) | |
tree | f04920f08eb4e481ce27bd1d96862676dff735dc /spec/lib/gitlab/metrics | |
parent | d2ffc30fd583e86d4122bb5061098f4f3ca7b3f1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/metrics')
-rw-r--r-- | spec/lib/gitlab/metrics/exporter/base_exporter_spec.rb | 16 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/exporter/web_exporter_spec.rb | 64 |
2 files changed, 71 insertions, 9 deletions
diff --git a/spec/lib/gitlab/metrics/exporter/base_exporter_spec.rb b/spec/lib/gitlab/metrics/exporter/base_exporter_spec.rb index 0376da13595..47ec69e2f45 100644 --- a/spec/lib/gitlab/metrics/exporter/base_exporter_spec.rb +++ b/spec/lib/gitlab/metrics/exporter/base_exporter_spec.rb @@ -19,15 +19,11 @@ describe Gitlab::Metrics::Exporter::BaseExporter do BindAddress: anything, Logger: anything, AccessLog: anything - ).and_wrap_original do |m, *args| - m.call(DoNotListen: true, Logger: args.first[:Logger]) - end - - allow_any_instance_of(::WEBrick::HTTPServer).to receive(:start) + ).and_call_original allow(settings).to receive(:enabled).and_return(true) - allow(settings).to receive(:port).and_return(8082) - allow(settings).to receive(:address).and_return('localhost') + allow(settings).to receive(:port).and_return(0) + allow(settings).to receive(:address).and_return('127.0.0.1') end after do @@ -61,6 +57,8 @@ describe Gitlab::Metrics::Exporter::BaseExporter do m.call(DoNotListen: true, Logger: args.first[:Logger]) end + allow_any_instance_of(::WEBrick::HTTPServer).to receive(:start) + exporter.start.join end end @@ -89,14 +87,14 @@ describe Gitlab::Metrics::Exporter::BaseExporter do describe 'when exporter is running' do before do - exporter.start.join + exporter.start end describe '#start' do it "doesn't start running server" do expect_any_instance_of(::WEBrick::HTTPServer).not_to receive(:start) - expect { exporter.start.join }.not_to change { exporter.thread? } + expect { exporter.start }.not_to change { exporter.thread? } end end diff --git a/spec/lib/gitlab/metrics/exporter/web_exporter_spec.rb b/spec/lib/gitlab/metrics/exporter/web_exporter_spec.rb new file mode 100644 index 00000000000..99349934e63 --- /dev/null +++ b/spec/lib/gitlab/metrics/exporter/web_exporter_spec.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Metrics::Exporter::WebExporter do + let(:exporter) { described_class.new } + + context 'when blackout seconds is used' do + let(:blackout_seconds) { 0 } + let(:readiness_probe) { exporter.send(:readiness_probe).execute } + + before do + stub_config( + monitoring: { + web_exporter: { + enabled: true, + port: 0, + address: '127.0.0.1', + blackout_seconds: blackout_seconds + } + } + ) + + exporter.start + end + + after do + exporter.stop + end + + context 'when running server' do + it 'readiness probe returns succesful status' do + expect(readiness_probe.http_status).to eq(200) + expect(readiness_probe.json).to include(status: 'ok') + expect(readiness_probe.json).to include('web_exporter' => [{ 'status': 'ok' }]) + end + end + + context 'when blackout seconds is 10s' do + let(:blackout_seconds) { 10 } + + it 'readiness probe returns a failure status' do + # during sleep we check the status of readiness probe + expect(exporter).to receive(:sleep).with(10) do + expect(readiness_probe.http_status).to eq(503) + expect(readiness_probe.json).to include(status: 'failed') + expect(readiness_probe.json).to include('web_exporter' => [{ 'status': 'failed' }]) + end + + exporter.stop + end + end + + context 'when blackout is disabled' do + let(:blackout_seconds) { 0 } + + it 'readiness probe returns a failure status' do + expect(exporter).not_to receive(:sleep) + + exporter.stop + end + end + end +end |