circuitbox 0.10.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0f2e7b33bd03af9f5b4aa606de11a0a1068b931
4
- data.tar.gz: 922098a0bf91d9c782c3ac147e94af11f834cf94
3
+ metadata.gz: 7d3753a1304b550e062e4956cb9c4ddd366a1916
4
+ data.tar.gz: 837d1d4e71f5ddaa3b9434d6333d846043d73303
5
5
  SHA512:
6
- metadata.gz: e1fefde3c0c5af41966ff72eee0c71d3c0e5478306b3f744b95eed5ea4e5daeb651ecaf0cf0f7a92eb354571b0af3628c48881e3b29b0f291b8c1a8f1da57adb
7
- data.tar.gz: 34add156e9af7dd00a3a12be2c6dde1d05e7f8c5ab5bfcb7006022351ddcbccc57586b340bd6d4b8323bb71cfc02022a49e5fef0bf8afbc88df0288edd93822b
6
+ metadata.gz: e12e4b470624fc64ca42ada7b624c4233b0d8f80d6ac98d244833a0de261ef3d0e09b11205e6740a3a24514cccad03a959780dc9cae75f56a6ac83ee26435186
7
+ data.tar.gz: 5a81d87b4a22644b5ea2bacf5a3ee2193ddbd896b15991f41ca9a21ae446fc74a844938cc9b761e2afe38b273cea4be184b84e43d892761d5c6d185e34478f58
data/README.md CHANGED
@@ -94,7 +94,7 @@ class CircuitOpenException < StandardError ; end
94
94
 
95
95
  ActiveSupport::Notifications.subscribe('circuit_open') do |name, start, finish, id, payload|
96
96
  circuit_name = payload[:circuit]
97
- Rails.logger.warning("Open circuit for: #{circuit_name}")
97
+ Rails.logger.warn("Open circuit for: #{circuit_name}")
98
98
  end
99
99
  ActiveSupport::Notifications.subscribe('circuit_close') do |name, start, finish, id, payload|
100
100
  circuit_name = payload[:circuit]
@@ -196,17 +196,21 @@ conn.get("/api", circuit_breaker_run_options: {})
196
196
  c.use Circuitbox::FaradayMiddleware, circuit_breaker_options: {}
197
197
  ```
198
198
 
199
- <<<<<<< HEAD
200
- * `open_circuit` lambda determining what response is considered a failure,
199
+ * `open_circuit` lambda determining what response is considered a failure,
201
200
  counting towards the opening of the circuit
202
201
 
203
202
  ```ruby
204
203
  c.use Circuitbox::FaradayMiddleware, open_circuit: lambda { |response| response.status >= 500 }
205
204
  ```
205
+
206
206
  ## CHANGELOG
207
- <<<<<<< HEAD
207
+
208
208
  ### version next
209
209
 
210
+ ### v0.10.1
211
+ - [Documentation fix](https://github.com/yammer/circuitbox/pull/29) [chiefcll](https://github.com/chiefcll)
212
+ - [Faraday middleware fix](https://github.com/yammer/circuitbox/pull/30) [chiefcll](https://github.com/chiefcll)
213
+
210
214
  ### v0.10
211
215
  - configuration option for faraday middleware for what should be considered to open the circuit [enrico-scalavio](https://github.com/enrico-scalavino)
212
216
  - fix for issue 16, support of in_parallel requests in faraday middlware which were opening the circuit.
@@ -29,7 +29,6 @@ class Circuitbox
29
29
 
30
30
  def call(request_env)
31
31
  service_response = nil
32
- check_circuit_open!(request_env)
33
32
  circuit(request_env).run!(run_options(request_env)) do
34
33
  @app.call(request_env).on_complete do |env|
35
34
  service_response = Faraday::Response.new(env)
@@ -50,11 +49,6 @@ class Circuitbox
50
49
 
51
50
  private
52
51
 
53
- def check_circuit_open!(env)
54
- # raises if the circuit is open
55
- circuit(env).run!(run_options(env)) { :noop }
56
- end
57
-
58
52
  def run_options(env)
59
53
  env[:circuit_breaker_run_options] || {}
60
54
  end
@@ -64,8 +58,7 @@ class Circuitbox
64
58
 
65
59
  @circuit_breaker_options = opts.fetch(:circuit_breaker_options, {})
66
60
  @circuit_breaker_options.merge!(
67
- exceptions: opts.fetch(:exceptions, DEFAULT_EXCEPTIONS),
68
- volume_threshold: 10
61
+ exceptions: opts.fetch(:exceptions, DEFAULT_EXCEPTIONS)
69
62
  )
70
63
  end
71
64
 
@@ -1,3 +1,3 @@
1
1
  class Circuitbox
2
- VERSION='0.10.0'
2
+ VERSION='0.10.1'
3
3
  end
@@ -7,7 +7,7 @@ class Circuitbox
7
7
  class FaradayMiddlewareTest < Minitest::Test
8
8
 
9
9
  attr_reader :app
10
-
10
+
11
11
  def setup
12
12
  @app = gimme
13
13
  end
@@ -84,7 +84,7 @@ class Circuitbox
84
84
  env = { url: "url", circuit_breaker_run_options: :sential }
85
85
  middleware = FaradayMiddleware.new(app, circuitbox: circuitbox)
86
86
  middleware.call(env)
87
- verify(circuit, 2.times).run!(:sential) # one to check open, one to execute command
87
+ verify(circuit, 1.times).run!(:sential)
88
88
  end
89
89
 
90
90
  def test_pass_circuit_breaker_options
@@ -92,15 +92,14 @@ class Circuitbox
92
92
  env = { url: "url" }
93
93
  expected_circuit_breaker_options = {
94
94
  sential: :sential,
95
- exceptions: FaradayMiddleware::DEFAULT_EXCEPTIONS,
96
- volume_threshold: 10
95
+ exceptions: FaradayMiddleware::DEFAULT_EXCEPTIONS
97
96
  }
98
97
  give(circuitbox).circuit("url", expected_circuit_breaker_options) { circuit }
99
98
  options = { circuitbox: circuitbox, circuit_breaker_options: { sential: :sential } }
100
99
  middleware = FaradayMiddleware.new(app, options)
101
100
  middleware.call(env)
102
101
 
103
- verify(circuitbox, 2.times).circuit("url", expected_circuit_breaker_options)
102
+ verify(circuitbox, 1.times).circuit("url", expected_circuit_breaker_options)
104
103
  end
105
104
 
106
105
  def test_overwrite_circuitbreaker_default_value
@@ -2,7 +2,12 @@ require "integration_helper"
2
2
  require "typhoeus/adapters/faraday"
3
3
 
4
4
  class Circuitbox
5
+
5
6
  class FaradayMiddlewareTest < Minitest::Test
7
+ include IntegrationHelpers
8
+
9
+ attr_reader :connection, :success_url, :failure_url
10
+
6
11
  @@only_once = false
7
12
  def setup
8
13
  @connection = Faraday.new do |c|
@@ -22,30 +27,34 @@ class Circuitbox
22
27
  Circuitbox.reset
23
28
  end
24
29
 
30
+ def test_circuit_does_not_open_for_below_threshhold_failed_requests
31
+ 5.times { connection.get(failure_url) }
32
+ assert_equal connection.get(success_url).status, 200
33
+ end
34
+
25
35
  def test_failure_circuit_response
26
- failure_response = @connection.get(@failure_url)
36
+ failure_response = connection.get(failure_url)
27
37
  assert_equal failure_response.status, 503
28
38
  assert_match failure_response.original_response.body, "Failure!"
29
39
  end
30
40
 
31
41
  def test_open_circuit_response
32
- 10.times { @connection.get(@failure_url) } # make the CircuitBreaker open
33
-
34
- open_circuit_response = @connection.get(@failure_url)
42
+ open_circuit
43
+ open_circuit_response = connection.get(failure_url)
35
44
  assert_equal open_circuit_response.status, 503
36
45
  assert open_circuit_response.original_response.nil?
37
46
  end
38
47
 
39
48
  def test_closed_circuit_response
40
- result = @connection.get(@success_url)
49
+ result = connection.get(success_url)
41
50
  assert result.success?
42
51
  end
43
52
 
44
53
  def test_parallel_requests_closed_circuit_response
45
54
  response_1, response_2 = nil
46
- @connection.in_parallel do
47
- response_1 = @connection.get(@success_url)
48
- response_2 = @connection.get(@success_url)
55
+ connection.in_parallel do
56
+ response_1 = connection.get(success_url)
57
+ response_2 = connection.get(success_url)
49
58
  end
50
59
 
51
60
  assert response_1.success?
@@ -53,11 +62,11 @@ class Circuitbox
53
62
  end
54
63
 
55
64
  def test_parallel_requests_open_circuit_response
56
- 10.times { @connection.get(@failure_url) } # make the CircuitBreaker open
65
+ open_circuit
57
66
  response_1, response_2 = nil
58
- @connection.in_parallel do
59
- response_1 = @connection.get(@failure_url)
60
- response_2 = @connection.get(@failure_url)
67
+ connection.in_parallel do
68
+ response_1 = connection.get(failure_url)
69
+ response_2 = connection.get(failure_url)
61
70
  end
62
71
 
63
72
  assert_equal response_1.status, 503
@@ -38,3 +38,11 @@ class FakeServer
38
38
  sleep 0.5 # wait for the server to spin up
39
39
  end
40
40
  end
41
+
42
+ module IntegrationHelpers
43
+ def open_circuit
44
+ volume_threshold = Circuitbox['test'].option_value(:volume_threshold)
45
+ (volume_threshold + 1).times { connection.get(failure_url) }
46
+ end
47
+ end
48
+
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: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fahim Ferdous
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler