diff options
| author | mo khan <mo.khan@gmail.com> | 2020-04-13 16:05:08 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-04-13 16:05:08 -0600 |
| commit | 4dd4468ea697dc5580085660f4d3c3c4f6642252 (patch) | |
| tree | 1cb9cb831057e05ebbe522c924b59a2dcd897c54 /spec/unit/core/http_spec.rb | |
| parent | 6502e75fad98211108337ad863c5b49ff8a7b09e (diff) | |
Stop attempting connections to unreachable hosts
Diffstat (limited to 'spec/unit/core/http_spec.rb')
| -rw-r--r-- | spec/unit/core/http_spec.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/unit/core/http_spec.rb b/spec/unit/core/http_spec.rb new file mode 100644 index 0000000..b585db4 --- /dev/null +++ b/spec/unit/core/http_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +RSpec.describe ::Spandx::Core::Http do + subject { described_class.new(retries: 1) } + + describe '#get' do + context 'when a connection to a host failed previously' do + let(:down_host) { 'nexus.example.com' } + let(:up_host) { 'git.example.com' } + + before do + down_url = "https://#{down_host}/#{SecureRandom.uuid}" + stub_request(:get, down_url).to_timeout + subject.get(down_url) + end + + it 'stops attempting to connect to an unreachable host after `n` failures' do + another_down_url = "https://#{down_host}/#{SecureRandom.uuid}" + default_value = SecureRandom.uuid + + stub_request(:get, another_down_url).to_raise(StandardError) + + expect(subject.get(another_down_url, default: default_value)).to eql(default_value) + end + + it 'continues to connect to hosts that are still up' do + up_url = "https://#{up_host}/#{SecureRandom.uuid}" + + stub_request(:get, up_url).to_return(status: 200) + + expect(subject.get(up_url)).to be_a_kind_of(Net::HTTPSuccess) + end + end + end +end |
