dagger 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 447d77e66ec69445f5040231d19c038279d4ec7de624461deda078c544423ca9
4
- data.tar.gz: c5eb814e71fd6a37b3b4272f6f747654eeb157655dec65ae6ec6f0cf86d4e5ff
3
+ metadata.gz: 87d4e9c75ae13a7295e19686dd8064f08a9311d4271454f97ceeb8e14da46618
4
+ data.tar.gz: 84174088956cf7035c3a744be06900ca38ee011942d0bbca0cb68ae8ffd55a7d
5
5
  SHA512:
6
- metadata.gz: 31108057fbc3cd1d2e0c319d4c64244c596cbbb90d8ae6067945caedb2f8f7ff5c0fd144b16be55ac24cd36bbd466f08659b995b47ecd67425d26224bd505ede
7
- data.tar.gz: d996eaefa87c30682eb127d9f2f28cbb28363fcf2a2f758e32610d553937c05a35750316f043a6f4d2a9eb6727aad8f0351ca761ee62b326313b46e902764fd2
6
+ metadata.gz: 0d6aef88856f8a279c2540fc74cedb532d2fdbd287860bbd2458d30c20d34f37c84cd5c40578ce66238430233341a1eb86888f7248c3d5ba8023442a0a554582
7
+ data.tar.gz: b3debd2a802c83dbbafd69f06936c5ffbf2c73b0d62021bf02edd2ae1bc697a93c93a207b76dc9a15630342a71c8cf97acbab9826276076de3dfee7e2af8dc42
@@ -3,7 +3,7 @@ module Dagger
3
3
  class ConnectionManager
4
4
 
5
5
  def initialize(opts = {})
6
- @opts = {}
6
+ @opts = opts
7
7
  @active_connections = {}
8
8
  @mutex = Mutex.new
9
9
  end
@@ -1,7 +1,7 @@
1
1
  module Dagger
2
2
  MAJOR = 2
3
3
  MINOR = 0
4
- PATCH = 0
4
+ PATCH = 1
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].join('.')
7
7
  end
data/lib/dagger.rb CHANGED
@@ -40,7 +40,7 @@ module Dagger
40
40
  end
41
41
 
42
42
  def self.resolve_uri(uri, host = nil, query = nil)
43
- uri = host + uri if uri[0] == '/' && host
43
+ uri = host + uri if uri.to_s[0] == '/' && host
44
44
  uri = parse_uri(uri.to_s)
45
45
  uri.path.sub!(/\?.*|$/, '?' + to_query_string(query)) if query and query.any?
46
46
  uri
@@ -91,7 +91,7 @@ module Dagger
91
91
  def self.init_connection(uri, opts = {})
92
92
  http = Net::HTTP.new(opts[:ip] || uri.host, uri.port)
93
93
 
94
- if uri.port == 443
94
+ if uri.port == 443 || uri.scheme == 'https'
95
95
  http.use_ssl = true if http.respond_to?(:use_ssl=) # persistent does it automatically
96
96
  http.verify_mode = opts[:verify_ssl] === false ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
97
97
  end
@@ -0,0 +1,61 @@
1
+ require './lib/dagger'
2
+
3
+ require 'rspec/mocks'
4
+ require 'rspec/expectations'
5
+
6
+ describe 'Retries' do
7
+
8
+ def send_request
9
+ Dagger.get('http://foobar.com/test', opts)
10
+ end
11
+
12
+ let(:fake_http) { double('Net::HTTP', started?: true, "keep_alive_timeout=": true, "open_timeout=": true, "read_timeout=": true) }
13
+ let(:fake_resp) { double('Net::HTTPResponse', code: 200, body: 'foo') }
14
+
15
+ before do
16
+ allow(Net::HTTP).to receive(:new).at_least(:once).and_return(fake_http)
17
+ allow(fake_http).to receive(:verify_mode=).and_return(true)
18
+ end
19
+
20
+ describe 'on ECONNREFUSED' do
21
+
22
+ context 'if no retries option passed' do
23
+
24
+ let(:opts) { {} }
25
+
26
+ it 'does not retry request, and raises error' do
27
+ expect(fake_http).to receive(:request).once.and_raise(Errno::ECONNREFUSED)
28
+ expect { send_request }.to raise_error(Errno::ECONNREFUSED)
29
+ end
30
+
31
+ end
32
+
33
+ context 'if retries is 1' do
34
+
35
+ let(:opts) { { retries: 1, retry_wait: 1 } }
36
+
37
+ context 'and it still fails' do
38
+
39
+ it 'sends a second request, and raises error' do
40
+ expect(fake_http).to receive(:request).twice.and_raise(Errno::ECONNREFUSED)
41
+ expect { send_request }.to raise_error(Errno::ECONNREFUSED)
42
+ end
43
+
44
+ end
45
+
46
+ context 'and then it works' do
47
+
48
+ it 'sends a second request, and does not raise error' do
49
+ expect(fake_http).to receive(:request).once.and_raise(Errno::ECONNREFUSED)
50
+ expect(fake_http).to receive(:request).once.and_return(fake_resp)
51
+ allow(fake_resp).to receive(:[]).with('Content-Type').and_return('text/plain')
52
+
53
+ expect(send_request.body).to eq('foo')
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás Pollak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-24 00:00:00.000000000 Z
11
+ date: 2022-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -120,6 +120,7 @@ files:
120
120
  - spec/ip_connect_spec.rb
121
121
  - spec/parsers_spec.rb
122
122
  - spec/persistent_spec.rb
123
+ - spec/retries_spec.rb
123
124
  - spec/sending_data_spec.rb
124
125
  homepage: https://github.com/tomas/dagger
125
126
  licenses: []