diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-26 03:07:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-26 03:07:58 +0300 |
commit | 101c30f4dffc624af3cbe3f12edc2cfee570a5f3 (patch) | |
tree | ce7c63b2d73a42ad41d004020410871968974537 /spec | |
parent | e1549c75843d235607aebac9ed64f2fd10e549ed (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/prometheus_client_spec.rb | 20 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 8 | ||||
-rw-r--r-- | spec/services/clusters/applications/prometheus_health_check_service_spec.rb | 113 |
3 files changed, 141 insertions, 0 deletions
diff --git a/spec/lib/gitlab/prometheus_client_spec.rb b/spec/lib/gitlab/prometheus_client_spec.rb index 5eb133a5bf4..e869a384b29 100644 --- a/spec/lib/gitlab/prometheus_client_spec.rb +++ b/spec/lib/gitlab/prometheus_client_spec.rb @@ -16,6 +16,26 @@ describe Gitlab::PrometheusClient do end end + describe '#healthy?' do + it 'returns true when status code is 200 and healthy response body' do + stub_request(:get, subject.health_url).to_return(status: 200, body: described_class::HEALTHY_RESPONSE) + + expect(subject.healthy?).to eq(true) + end + + it 'returns false when status code is 200 and unhealthy response body' do + stub_request(:get, subject.health_url).to_return(status: 200, body: '') + + expect(subject.healthy?).to eq(false) + end + + it 'raises error when status code not 200' do + stub_request(:get, subject.health_url).to_return(status: 500, body: '') + + expect { subject.healthy? }.to raise_error(Gitlab::PrometheusClient::Error) + end + end + # This shared examples expect: # - query_url: A query URL # - execute_query: A query call diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 137795dcbc3..f37e39a9ee9 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -3223,6 +3223,14 @@ describe MergeRequest do subject.mark_as_unmergeable end + it 'notifies conflict, with enabled async mergability check' do + expect(notification_service).to receive(:merge_request_unmergeable).with(subject).once + expect(todo_service).to receive(:merge_request_became_unmergeable).with(subject).once + + subject.mark_as_checking + subject.mark_as_unmergeable + end + it 'does not notify whenever merge request is newly unmergeable due to other reasons' do allow(subject.project.repository).to receive(:can_be_merged?).and_return(true) diff --git a/spec/services/clusters/applications/prometheus_health_check_service_spec.rb b/spec/services/clusters/applications/prometheus_health_check_service_spec.rb new file mode 100644 index 00000000000..5c4127e4938 --- /dev/null +++ b/spec/services/clusters/applications/prometheus_health_check_service_spec.rb @@ -0,0 +1,113 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Clusters::Applications::PrometheusHealthCheckService, '#execute' do + let(:service) { described_class.new(cluster) } + + subject { service.execute } + + RSpec.shared_examples 'no alert' do + it 'does not send alert' do + expect(Projects::Alerting::NotifyService).not_to receive(:new) + + subject + end + end + + RSpec.shared_examples 'sends alert' do + it 'sends an alert' do + expect_next_instance_of(Projects::Alerting::NotifyService) do |notify_service| + expect(notify_service).to receive(:execute).with(alerts_service.token) + end + + subject + end + end + + RSpec.shared_examples 'correct health stored' do + it 'stores the correct health of prometheus app' do + subject + + expect(prometheus.healthy).to eq(client_healthy) + end + end + + context 'when cluster is not project_type' do + let(:cluster) { create(:cluster, :instance) } + + it { expect { subject }.to raise_error(RuntimeError, 'Invalid cluster type. Only project types are allowed.') } + end + + context 'when cluster is project_type' do + let_it_be(:alerts_service) { create(:alerts_service) } + let_it_be(:project) { create(:project, alerts_service: alerts_service) } + let(:applications_prometheus_healthy) { true } + let(:prometheus) { create(:clusters_applications_prometheus, status: prometheus_status_value, healthy: applications_prometheus_healthy) } + let(:cluster) { create(:cluster, :project, application_prometheus: prometheus, projects: [project]) } + + context 'when prometheus not installed' do + let(:prometheus_status_value) { Clusters::Applications::Prometheus.state_machine.states[:installing].value } + + it { expect(subject).to eq(nil) } + include_examples 'no alert' + end + + context 'when prometheus installed' do + let(:prometheus_status_value) { Clusters::Applications::Prometheus.state_machine.states[:installed].value } + + before do + client = instance_double('PrometheusClient', healthy?: client_healthy) + expect(prometheus).to receive(:prometheus_client).and_return(client) + end + + context 'when newly unhealthy' do + let(:applications_prometheus_healthy) { true } + let(:client_healthy) { false } + + include_examples 'sends alert' + include_examples 'correct health stored' + end + + context 'when newly healthy' do + let(:applications_prometheus_healthy) { false } + let(:client_healthy) { true } + + include_examples 'no alert' + include_examples 'correct health stored' + end + + context 'when continuously unhealthy' do + let(:applications_prometheus_healthy) { false } + let(:client_healthy) { false } + + include_examples 'no alert' + include_examples 'correct health stored' + end + + context 'when continuously healthy' do + let(:applications_prometheus_healthy) { true } + let(:client_healthy) { true } + + include_examples 'no alert' + include_examples 'correct health stored' + end + + context 'when first health check and healthy' do + let(:applications_prometheus_healthy) { nil } + let(:client_healthy) { true } + + include_examples 'no alert' + include_examples 'correct health stored' + end + + context 'when first health check and not healthy' do + let(:applications_prometheus_healthy) { nil } + let(:client_healthy) { false } + + include_examples 'sends alert' + include_examples 'correct health stored' + end + end + end +end |