From ad6ac17c5434f7eb87005dc3603b4ae9409c333f Mon Sep 17 00:00:00 2001 From: Jose Ivan Vargas Date: Fri, 28 Apr 2017 15:20:58 -0500 Subject: [PATCH] Added rescue block for the test method for the prometheus service --- .../unreleased/prometheus-integration-test-setting-fix.yml | 4 ++++ lib/gitlab/prometheus.rb | 6 +++++- spec/models/project_services/prometheus_service_spec.rb | 5 +++-- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/prometheus-integration-test-setting-fix.yml diff --git a/changelogs/unreleased/prometheus-integration-test-setting-fix.yml b/changelogs/unreleased/prometheus-integration-test-setting-fix.yml new file mode 100644 index 00000000000..c65c682a114 --- /dev/null +++ b/changelogs/unreleased/prometheus-integration-test-setting-fix.yml @@ -0,0 +1,4 @@ +--- +title: Added rescue block for the test method +merge_request: 10994 +author: diff --git a/lib/gitlab/prometheus.rb b/lib/gitlab/prometheus.rb index 62239779454..37afec5e7df 100644 --- a/lib/gitlab/prometheus.rb +++ b/lib/gitlab/prometheus.rb @@ -49,7 +49,11 @@ module Gitlab end def get(url) - handle_response(HTTParty.get(url)) + begin + handle_response(HTTParty.get(url)) + rescue SocketError + raise PrometheusError, "Can't connect to #{url}" + end end def handle_response(response) diff --git a/spec/models/project_services/prometheus_service_spec.rb b/spec/models/project_services/prometheus_service_spec.rb index d15079b686b..5ef1b53be15 100644 --- a/spec/models/project_services/prometheus_service_spec.rb +++ b/spec/models/project_services/prometheus_service_spec.rb @@ -93,11 +93,12 @@ describe PrometheusService, models: true, caching: true do [404, 500].each do |status| context "when Prometheus responds with #{status}" do + body_response = 'QUERY_FAILED' before do - stub_all_prometheus_requests(environment.slug, status: status, body: 'QUERY FAILED!') + stub_all_prometheus_requests(environment.slug, status: status, body: body_response) end - it { is_expected.to eq(success: false, result: %(#{status} - "QUERY FAILED!")) } + it { is_expected.to eq(success: false, result: %(#{status} - \"#{body_response}\")) } end end end