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 +4 -4
- data/lib/dagger/connection_manager.rb +1 -1
- data/lib/dagger/version.rb +1 -1
- data/lib/dagger.rb +2 -2
- data/spec/retries_spec.rb +61 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87d4e9c75ae13a7295e19686dd8064f08a9311d4271454f97ceeb8e14da46618
|
4
|
+
data.tar.gz: 84174088956cf7035c3a744be06900ca38ee011942d0bbca0cb68ae8ffd55a7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d6aef88856f8a279c2540fc74cedb532d2fdbd287860bbd2458d30c20d34f37c84cd5c40578ce66238430233341a1eb86888f7248c3d5ba8023442a0a554582
|
7
|
+
data.tar.gz: b3debd2a802c83dbbafd69f06936c5ffbf2c73b0d62021bf02edd2ae1bc697a93c93a207b76dc9a15630342a71c8cf97acbab9826276076de3dfee7e2af8dc42
|
data/lib/dagger/version.rb
CHANGED
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.
|
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:
|
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: []
|