From baae348eb8359db1500db7f710f9790db2521f8a Mon Sep 17 00:00:00 2001 From: eamon Date: Thu, 4 Jun 2020 17:39:45 +0800 Subject: [PATCH] fix logic flow and test --- resiliency/06_circuit_breaker/circuit_breaker_adv.go | 4 ++-- resiliency/06_circuit_breaker/circuit_breaker_test.go | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/resiliency/06_circuit_breaker/circuit_breaker_adv.go b/resiliency/06_circuit_breaker/circuit_breaker_adv.go index 437386c..4b8f11f 100644 --- a/resiliency/06_circuit_breaker/circuit_breaker_adv.go +++ b/resiliency/06_circuit_breaker/circuit_breaker_adv.go @@ -96,15 +96,15 @@ func (rb *RequestBreaker) beforeRequest() error { rb.options.Expiry = time.Now().Add(rb.options.Timeout) return nil } + return ErrTooManyRequests case StateClosed: if rb.options.Expiry.Before(time.Now()) { rb.cnter.Reset() rb.options.Expiry = time.Now().Add(rb.options.Interval) } - } - return ErrTooManyRequests + return nil } diff --git a/resiliency/06_circuit_breaker/circuit_breaker_test.go b/resiliency/06_circuit_breaker/circuit_breaker_test.go index d35468e..38c81fe 100644 --- a/resiliency/06_circuit_breaker/circuit_breaker_test.go +++ b/resiliency/06_circuit_breaker/circuit_breaker_test.go @@ -71,6 +71,8 @@ func TestObjectBreaker(t *testing.T) { } fmt.Println(string(body.([]byte))) + + log.Print("\nresult:", body.([]byte)) } func TestFunctionalBreaker(t *testing.T) {