File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ def refresh_state
7979
8080 def record_error
8181 now = RedisClient . now
82- expiry = now - @error_timeout
82+ expiry = now - @error_threshold_timeout
8383 @lock . synchronize do
8484 if @state == :closed
8585 @errors . reject! { |t | t < expiry }
@@ -100,6 +100,7 @@ def record_success
100100
101101 @successes += 1
102102 if @successes >= @success_threshold
103+ @errors . clear
103104 @state = :closed
104105 end
105106 end
Original file line number Diff line number Diff line change @@ -21,6 +21,18 @@ def test_open_circuit_after_consecutive_errors
2121 assert_open @circuit_breaker
2222 end
2323
24+ def test_track_errors_during_error_threshold_window
25+ assert_closed @circuit_breaker
26+ ( @circuit_breaker . error_threshold - 1 ) . times do
27+ record_error @circuit_breaker
28+ end
29+
30+ travel ( @circuit_breaker . error_threshold_timeout - 0.01 ) do
31+ record_error @circuit_breaker
32+ assert_open @circuit_breaker
33+ end
34+ end
35+
2436 def test_allow_use_after_the_errors_timedout
2537 open_circuit @circuit_breaker
2638 assert_open @circuit_breaker
You can’t perform that action at this time.
0 commit comments