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 +4 -4
- data/lib/breaker.rb +2 -4
- data/lib/breaker/test_cases.rb +31 -5
- data/lib/breaker/version.rb +1 -1
- data/test/acceptance_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a4311ad34e8bbc2fcca6687abcf024fefc4261a
|
4
|
+
data.tar.gz: c77e65d65615794de6ecce5b6a3a0c52b70381d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a9d766120aaffe57c111b316e883376885a825ca698f38f280893afe97c9497aecf964b26b1e7025c79c4b236198bc3656bc5f08ab46ececbc92d43f97cc820
|
7
|
+
data.tar.gz: f05c282d99e9a8dd5153300233a6c1ee9e37f8d4ab2ec80f0daee4baa55f46d8aec2d484cbe63eac6f74c987e0787054add600ed7c9b73115b22d04678b525e2
|
data/lib/breaker.rb
CHANGED
@@ -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
|
119
|
+
fuse.failure_count > fuse.failure_threshold
|
122
120
|
end
|
123
121
|
|
124
122
|
def half_open?(clock)
|
data/lib/breaker/test_cases.rb
CHANGED
@@ -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:
|
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.
|
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
|
-
|
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:
|
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
|
data/lib/breaker/version.rb
CHANGED
data/test/acceptance_test.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2014-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|