routemaster-drain 3.0.3 → 3.1.0

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
  SHA1:
3
- metadata.gz: 20836569e8aa8a67a439df2f2704bf04fa68c49e
4
- data.tar.gz: e016b966b80009d099b3064d0365c81dfad16c92
3
+ metadata.gz: eb1cccd206b6825ce76f748a269bfbc261ff4328
4
+ data.tar.gz: a05de95ccc0c4643015f69aeeb7bbf02c4905d4f
5
5
  SHA512:
6
- metadata.gz: 1d760e39869afb8b337ba935a405efb724b939fffaec97ce584d43de38bba2e551c5bfce3620d06f51fd714505e15e34d53c4df012d29076e7db8e0d3b7d8e48
7
- data.tar.gz: 86c704f1e0d04e23a854cb2025ca3a687d54eb30c0dcd40c816c57ebc3b506ad880ef37f9ed918226fe1c1afc9717e2dcc1621fea44034af3531010cddd7da31
6
+ metadata.gz: cb053523998b5303d8c47d52963c27fac7a87181f28a33ed0a84e8739103c8031bbb3955567440a229eb0691b8878da257c585d5bcd05ac1ae5d1ba5a6028c39
7
+ data.tar.gz: db39fcb620c32576258a6f94ebc70eaed859cd3b5ea61f4ac899fec68df30ed7f9170cb2535b035a2c40de6425a93cd2b87b99f0e3096e6381fafacc3a3be0cb
@@ -1,3 +1,9 @@
1
+ ### 3.1.0 (2017-11-42)
2
+
3
+ Features:
4
+
5
+ - Make retry-attempt-count and retry-methods configurable in APIClient.
6
+
1
7
  ### 3.0.3 (2017-09-21)
2
8
 
3
9
  Bug fixes:
@@ -34,17 +34,14 @@ module Routemaster
34
34
  # all the time to fetch the root resource before doing anything else.
35
35
  @@root_resources = {}
36
36
 
37
- def initialize(middlewares: [],
38
- listener: nil,
39
- response_class: nil,
40
- metrics_client: nil,
41
- source_peer: nil)
42
-
43
- @listener = listener
44
- @middlewares = middlewares
45
- @default_response_class = response_class
46
- @metrics_client = metrics_client
47
- @source_peer = source_peer
37
+ def initialize(options = {})
38
+ @listener = options.fetch :listener, nil
39
+ @middlewares = options.fetch :middlewares, []
40
+ @default_response_class = options.fetch :response_class, nil
41
+ @metrics_client = options.fetch :metrics_client, nil
42
+ @source_peer = options.fetch :source_peer, nil
43
+ @retry_attempts = options.fetch :retry_attempts, 2
44
+ @retry_methods = options.fetch :retry_methods, Faraday::Request::Retry::IDEMPOTENT_METHODS
48
45
 
49
46
  connection # warm up connection so Faraday does all it's magical file loading in the main thread
50
47
  end
@@ -123,7 +120,11 @@ module Routemaster
123
120
  def connection
124
121
  @connection ||= Faraday.new do |f|
125
122
  f.request :json
126
- f.request :retry, max: 2, interval: 100e-3, backoff_factor: 2
123
+ f.request :retry,
124
+ max: @retry_attempts,
125
+ interval: 100e-3,
126
+ backoff_factor: 2,
127
+ methods: @retry_methods
127
128
  f.response :mashify
128
129
  f.response :json, content_type: /\bjson/
129
130
  f.use Routemaster::Middleware::ResponseCaching, listener: @listener
@@ -1,5 +1,5 @@
1
1
  module Routemaster
2
2
  module Drain
3
- VERSION = '3.0.3'.freeze
3
+ VERSION = '3.1.0'.freeze
4
4
  end
5
5
  end
@@ -159,24 +159,65 @@ describe Routemaster::APIClient do
159
159
  end
160
160
 
161
161
  describe '#patch' do
162
- subject { fetcher.patch(url, body: {}, headers: headers) }
162
+ let(:body) { { 'one' => 1, 'two' => 2 }.to_json }
163
+ subject { fetcher.patch(url, body: body, headers: headers) }
163
164
 
164
- before do
165
- @patch_req = stub_request(:patch, /example\.com/).to_return(
166
- status: 200,
167
- body: { id: 132, type: 'widget' }.to_json,
168
- headers: {
169
- 'content-type' => 'application/json;v=1'
170
- }
171
- )
172
- end
165
+ context 'when request succeeds' do
166
+ before do
167
+ @patch_req = stub_request(:patch, /example\.com/).to_return(
168
+ status: 200,
169
+ body: { id: 132, type: 'widget' }.to_json,
170
+ headers: {
171
+ 'content-type' => 'application/json;v=1'
172
+ }
173
+ )
174
+ end
173
175
 
174
- it 'PATCH from the URL' do
175
- subject
176
- expect(@patch_req).to have_been_requested
176
+ it 'PATCH from the URL' do
177
+ subject
178
+ expect(@patch_req).to have_been_requested
179
+ end
180
+
181
+ it_behaves_like 'a wrappable response'
177
182
  end
178
183
 
179
- it_behaves_like 'a wrappable response'
184
+ context 'when request times out' do
185
+ subject do
186
+ begin
187
+ fetcher.patch(url, body: body, headers: headers)
188
+ rescue Faraday::TimeoutError
189
+ end
190
+ end
191
+
192
+ before do
193
+ stub_request(:patch, url).to_timeout
194
+ end
195
+
196
+ it 'tries the PATCH request only once' do
197
+ subject
198
+ assert_requested(:patch, url, body: body, times: 1)
199
+ end
200
+
201
+ context 'when PATCH is specified as a method to retry' do
202
+ let(:retry_methods) { [:patch] }
203
+ let(:fetcher) { described_class.new(retry_methods: retry_methods) }
204
+
205
+ it 'tries the PATCH request 3 times' do
206
+ subject
207
+ assert_requested(:patch, url, body: body, times: 3)
208
+ end
209
+
210
+ context 'when retry attempt count is specified' do
211
+ let(:retry_attempts) { 4 }
212
+ let(:fetcher) { described_class.new(retry_methods: retry_methods, retry_attempts: retry_attempts) }
213
+
214
+ it "tries the PATCH request '1 + retry-count' times" do
215
+ subject
216
+ assert_requested(:patch, url, body: body, times: 1 + retry_attempts)
217
+ end
218
+ end
219
+ end
220
+ end
180
221
  end
181
222
 
182
223
  describe '#delete' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: routemaster-drain
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Letessier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-21 00:00:00.000000000 Z
11
+ date: 2017-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -270,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
270
  version: '0'
271
271
  requirements: []
272
272
  rubyforge_project:
273
- rubygems_version: 2.6.13
273
+ rubygems_version: 2.6.11
274
274
  signing_key:
275
275
  specification_version: 4
276
276
  summary: Event receiver for the Routemaster bus
@@ -317,4 +317,3 @@ test_files:
317
317
  - spec/support/uses_dotenv.rb
318
318
  - spec/support/uses_redis.rb
319
319
  - spec/support/uses_webmock.rb
320
- has_rdoc: