breaker 0.1.0 → 0.1.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
  SHA1:
3
- metadata.gz: e96a4a527f8764f01191e363daf25d59bcfc44a1
4
- data.tar.gz: 9707df9e63bbdce0166b471beab29456f67c5c6b
3
+ metadata.gz: 2a4311ad34e8bbc2fcca6687abcf024fefc4261a
4
+ data.tar.gz: c77e65d65615794de6ecce5b6a3a0c52b70381d8
5
5
  SHA512:
6
- metadata.gz: 43cb66bf520aa9d6abd763b274b195a2a64387215c7c31799430f576a742f602dc8ac466edd3b88bcb948d37ade1b5a0f9ac98559ae2673afa9dc1358f4e1dbc
7
- data.tar.gz: 4436478a597986c372c032ac72bf0dea6977a2b34b27cfc294113746f6bb6ef4bdf1d454c47d90a794364c57d1421c172b25a218a1e1ae86345bc4a3ebdc0715
6
+ metadata.gz: 4a9d766120aaffe57c111b316e883376885a825ca698f38f280893afe97c9497aecf964b26b1e7025c79c4b236198bc3656bc5f08ab46ececbc92d43f97cc820
7
+ data.tar.gz: f05c282d99e9a8dd5153300233a6c1ee9e37f8d4ab2ec80f0daee4baa55f46d8aec2d484cbe63eac6f74c987e0787054add600ed7c9b73115b22d04678b525e2
@@ -50,7 +50,6 @@ module Breaker
50
50
  end
51
51
 
52
52
  def open(clock = Time.now)
53
- fuse.failure_count = 1
54
53
  fuse.state = :open
55
54
  fuse.retry_threshold = clock + retry_timeout
56
55
  end
@@ -105,9 +104,8 @@ module Breaker
105
104
  result
106
105
  rescue => ex
107
106
  fuse.failure_count = fuse.failure_count + 1
108
- fuse.retry_threshold = clock + retry_timeout
109
107
 
110
- open clock
108
+ open clock if tripped?
111
109
 
112
110
  raise ex
113
111
  end
@@ -118,7 +116,7 @@ module Breaker
118
116
 
119
117
  private
120
118
  def tripped?
121
- fuse.failure_count != 0
119
+ fuse.failure_count > fuse.failure_threshold
122
120
  end
123
121
 
124
122
  def half_open?(clock)
@@ -18,10 +18,21 @@ module Breaker
18
18
  end
19
19
 
20
20
  def test_goes_into_open_state_when_failure_threshold_reached
21
- circuit = Breaker.circuit 'test', failure_threshold: 1, retry_timeout: 30
21
+ circuit = Breaker.circuit 'test', failure_threshold: 5, retry_timeout: 30
22
22
 
23
23
  assert circuit.closed?
24
24
 
25
+ circuit.failure_threshold.times do
26
+ begin
27
+ circuit.run do
28
+ raise DummyError
29
+ end
30
+ rescue DummyError ; end
31
+ end
32
+
33
+ assert_equal circuit.failure_count, circuit.failure_threshold
34
+ refute circuit.open?
35
+
25
36
  assert_raises DummyError do
26
37
  circuit.run do
27
38
  raise DummyError
@@ -29,6 +40,7 @@ module Breaker
29
40
  end
30
41
 
31
42
  assert circuit.open?
43
+
32
44
  assert_raises Breaker::CircuitOpenError do
33
45
  circuit.run do
34
46
  assert false, "Block should not run in this state"
@@ -40,12 +52,19 @@ module Breaker
40
52
  clock = Time.now
41
53
  circuit = Breaker.circuit 'test', failure_threshold: 2, retry_timeout: 15
42
54
 
43
- circuit.open clock
55
+ (circuit.failure_threshold + 1).times do
56
+ begin
57
+ circuit.run clock do
58
+ raise DummyError
59
+ end
60
+ rescue DummyError ; end
61
+ end
62
+
44
63
  assert circuit.open?
45
64
 
46
65
  assert_raises Breaker::CircuitOpenError do
47
66
  circuit.run clock do
48
- # nothing
67
+ # nothing
49
68
  end
50
69
  end
51
70
 
@@ -58,9 +77,16 @@ module Breaker
58
77
 
59
78
  def test_failures_in_half_open_state_push_retry_timeout_back
60
79
  clock = Time.now
61
- circuit = Breaker.circuit 'test', failure_threshold: 2, retry_timeout: 15
80
+ circuit = Breaker.circuit 'test', failure_threshold: 1, retry_timeout: 15
81
+
82
+ (circuit.failure_threshold + 1).times do
83
+ begin
84
+ circuit.run clock do
85
+ raise DummyError
86
+ end
87
+ rescue DummyError ; end
88
+ end
62
89
 
63
- circuit.open clock
64
90
  assert circuit.open?
65
91
 
66
92
  assert_raises DummyError do
@@ -1,3 +1,3 @@
1
1
  module Breaker
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -10,7 +10,7 @@ class AcceptanceTest < MiniTest::Unit::TestCase
10
10
 
11
11
  def setup
12
12
  @repo = Breaker::InMemoryRepo.new
13
- @fuse = InMemoryFuse.new :closed, 0, nil, 3, 15, 10
13
+ @fuse = InMemoryFuse.new :closed, 0, 1, 3, 15, 10
14
14
  super
15
15
  end
16
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ahawkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-14 00:00:00.000000000 Z
11
+ date: 2014-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler