Added rescue block for the test method for the prometheus service

This commit is contained in:
Jose Ivan Vargas 2017-04-28 15:20:58 -05:00
parent 91e8f7702c
commit ad6ac17c54
3 changed files with 12 additions and 3 deletions

View file

@ -0,0 +1,4 @@
---
title: Added rescue block for the test method
merge_request: 10994
author:

View file

@ -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)

View file

@ -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