fix logic flow and test

This commit is contained in:
eamon 2020-06-04 17:39:45 +08:00
parent 4ba68f1cbd
commit baae348eb8
2 changed files with 4 additions and 2 deletions

View File

@ -96,15 +96,15 @@ func (rb *RequestBreaker) beforeRequest() error {
rb.options.Expiry = time.Now().Add(rb.options.Timeout) rb.options.Expiry = time.Now().Add(rb.options.Timeout)
return nil return nil
} }
return ErrTooManyRequests
case StateClosed: case StateClosed:
if rb.options.Expiry.Before(time.Now()) { if rb.options.Expiry.Before(time.Now()) {
rb.cnter.Reset() rb.cnter.Reset()
rb.options.Expiry = time.Now().Add(rb.options.Interval) rb.options.Expiry = time.Now().Add(rb.options.Interval)
} }
} }
return ErrTooManyRequests return nil
} }

View File

@ -71,6 +71,8 @@ func TestObjectBreaker(t *testing.T) {
} }
fmt.Println(string(body.([]byte))) fmt.Println(string(body.([]byte)))
log.Print("\nresult:", body.([]byte))
} }
func TestFunctionalBreaker(t *testing.T) { func TestFunctionalBreaker(t *testing.T) {