Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remember last error and keep internal buffer of last N errors. fixed … #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kanekv
Copy link

@kanekv kanekv commented Apr 11, 2017

…unreliable timeout test

Fixes #45

@@ -153,12 +159,17 @@ func NewBreakerWithOptions(options *Options) *Breaker {
options.WindowBuckets = DefaultWindowBuckets
}

if options.ErrorHistoryDepth == 0 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if it's < 0? Should this be uint?

}

// Error returns last error from internal buffer
func (cb *Breaker) Error() error {
Copy link

@dtjm dtjm Apr 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename to LastError to avoid confusion with error interface


// Errors returns all errors from internal buffer
func (cb *Breaker) Errors() (errors []error) {
cb.errorsBuffer.Do(func(x interface{}) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will output the current error and then the rest.

errors ordered as 1 2 3 will be output as 3 1 2

func (cb *Breaker) Errors() (errors []error) {
cb.errorsBuffer.Do(func(x interface{}) {
if x != nil {
errors = append(errors, x.(error))
Copy link

@dtjm dtjm Apr 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might as well pre-allocate slice since you know the max number of elements

can allocate n + 1 and then move the first element to the end to get the correct ordering

@@ -302,7 +338,7 @@ func (cb *Breaker) Success() {
cb.backoffLock.Unlock()

state := cb.state()
if state == halfopen {
if state == halfopen || state == open {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comment why this is needed?

if errs[1].Error() != "circuit error" {
t.Fatalf("expected `%s` error, got %s", "circuit error", errs[0].Error())
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add test with empty error buffer

@dtjm
Copy link

dtjm commented May 4, 2017

Add test for race?

@dtjm
Copy link

dtjm commented Feb 17, 2018

@rubyist can this be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants