circuitbox 1.0.2 → 1.0.3

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: d76522a6fa77c9f707fdec676e5e1f85269f4f07
4
- data.tar.gz: 6ec1f0e24a71c79422cd34aac919387950dafb98
3
+ metadata.gz: f75524d25326132f1bac120effbfa9b130f95bf1
4
+ data.tar.gz: ee8a589ff7b55ea95f5e5d119e7c30fe7be4e640
5
5
  SHA512:
6
- metadata.gz: a981649408dcbd732c63cfa90793169427c43bbc4ef6e6dc4d45291a74fd95dbe44224ec096947d478fbd0d2e44e4e63bcc3362287f046cedf7110b3bb5ace85
7
- data.tar.gz: 1c9e9ddc9419cb80e6a99fca710d4a314c7a615fe315df7201a6063147d00296b931d540a8185968cd715fe310df2c5f625474a784e5e2e60c34630ef521eb86
6
+ metadata.gz: 280e82433f43b428b48ee4e5a5a713da46deb723f8df9d886b3e2bf1e7eb922a119c367a706f66d82ee5d731090580773de06030f451ea40784ae544218e1953
7
+ data.tar.gz: 1b64ba171cfe40c0956ed38f94cc3e37c3e848a051cc987a2944b7578362ab5f51992757208dea50559cb5338d3fcff9c7fa2537ba9df047bfb05f1dabbc4038
data/README.md CHANGED
@@ -218,9 +218,12 @@ use with Unicorn. It depends on the `daybreak` gem.
218
218
 
219
219
  ```ruby
220
220
  require "daybreak"
221
- Circuitbox.circuit :identifier, cache: Moneta.new(:Daybreak, file: "db.daybreak")
221
+ Circuitbox.circuit :identifier, cache: Moneta.new(:Daybreak, file: "db.daybreak", expires: true)
222
222
  ```
223
223
 
224
+ It is important for the store to have
225
+ [expires](https://github.com/minad/moneta#backend-feature-matrix) support.
226
+
224
227
  ## Faraday
225
228
 
226
229
  Circuitbox ships with [Faraday HTTP client](https://github.com/lostisland/faraday) middleware.
@@ -297,6 +300,12 @@ c.use Circuitbox::FaradayMiddleware, open_circuit: lambda { |response| response.
297
300
  ## CHANGELOG
298
301
  ### version next
299
302
 
303
+ ### v1.0.3
304
+ - fix timeout issue for default configuration, as default `:Memory` adapter does
305
+ not natively support expires, we need to actually load it on demand.
306
+ - fix memoization of `circuit_breaker_options` not actually doing memoization in
307
+ `excon` and `faraday` middleware.
308
+
300
309
  ### v1.0.2
301
310
  - Fix timeout issue [#51](https://github.com/yammer/circuitbox/issues/51)
302
311
  [sebastian-juliu](https://github.com/sebastian-julius)
@@ -36,7 +36,7 @@ class Circuitbox
36
36
  end
37
37
 
38
38
  def self.circuit_store
39
- self.instance.circuit_store ||= Moneta.new(:Memory)
39
+ self.instance.circuit_store ||= Moneta.new(:Memory, expires: true)
40
40
  end
41
41
 
42
42
  def self.circuit_store=(store)
@@ -86,7 +86,7 @@ class Circuitbox
86
86
  end
87
87
 
88
88
  def circuit_breaker_options
89
- return @circuit_breaker_options if @current_adapter
89
+ return @circuit_breaker_options if @circuit_breaker_options
90
90
 
91
91
  @circuit_breaker_options = opts.fetch(:circuit_breaker_options, {})
92
92
  @circuit_breaker_options.merge!(
@@ -63,7 +63,7 @@ class Circuitbox
63
63
  end
64
64
 
65
65
  def circuit_breaker_options
66
- return @circuit_breaker_options if @current_adapter
66
+ return @circuit_breaker_options if @circuit_breaker_options
67
67
 
68
68
  @circuit_breaker_options = opts.fetch(:circuit_breaker_options, {})
69
69
  @circuit_breaker_options.merge!(
@@ -1,3 +1,3 @@
1
1
  class Circuitbox
2
- VERSION='1.0.2'
2
+ VERSION='1.0.3'
3
3
  end
@@ -151,55 +151,29 @@ class CircuitBreakerTest < Minitest::Test
151
151
  end
152
152
 
153
153
  describe 'closing the circuit after sleep' do
154
- class GodTime < SimpleDelegator
155
- def now
156
- self
157
- end
158
-
159
- def initialize(now=nil)
160
- @now = now || Time.now
161
- super(@now)
162
- end
163
-
164
- def __getobj__
165
- @now
166
- end
167
-
168
- def __setobj__(obj)
169
- @now = obj
170
- end
171
-
172
- def jump(interval)
173
- __setobj__ @now + interval
174
- end
175
- end
176
-
177
154
  def cb_options
178
155
  {
179
- sleep_window: 70,
180
- time_window: 60,
156
+ sleep_window: 1,
157
+ time_window: 2,
181
158
  volume_threshold: 5,
182
- error_threshold: 33,
183
- timeout_seconds: 1,
184
- time_class: @timer
159
+ error_threshold: 5,
160
+ timeout_seconds: 1
185
161
  }
186
162
  end
187
163
 
188
164
  def setup
189
- @timer = GodTime.new
190
165
  @circuit = Circuitbox::CircuitBreaker.new(:yammer, cb_options)
191
166
  end
192
167
 
193
-
194
168
  it 'close the circuit after sleeping time' do
195
169
  # lets open the circuit
196
- 10.times { @circuit.run { raise RequestFailureError } }
170
+ (cb_options[:error_threshold] + 1).times { @circuit.run { raise RequestFailureError } }
197
171
  run_count = 0
198
172
  @circuit.run { run_count += 1 }
199
173
  assert_equal 0, run_count, 'circuit is not open'
174
+ # it is + 2 on purpose, because + 1 is flaky here
175
+ sleep cb_options[:sleep_window] + 2
200
176
 
201
- @timer.jump(cb_options[:sleep_window] + 1)
202
- @circuit.try_close_next_time
203
177
  @circuit.run { run_count += 1 }
204
178
  assert_equal 1, run_count, 'circuit is not closed'
205
179
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circuitbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fahim Ferdous
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-18 00:00:00.000000000 Z
11
+ date: 2016-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler