remember last error and keep internal buffer of last N errors. fixed …#46
Open
kanekv wants to merge 3 commits intorubyist:masterfrom
Open
remember last error and keep internal buffer of last N errors. fixed …#46kanekv wants to merge 3 commits intorubyist:masterfrom
kanekv wants to merge 3 commits intorubyist:masterfrom
Conversation
dtjm
reviewed
Apr 12, 2017
circuitbreaker.go
Outdated
| options.WindowBuckets = DefaultWindowBuckets | ||
| } | ||
|
|
||
| if options.ErrorHistoryDepth == 0 { |
dtjm
reviewed
Apr 12, 2017
circuitbreaker.go
Outdated
| } | ||
|
|
||
| // Error returns last error from internal buffer | ||
| func (cb *Breaker) Error() error { |
There was a problem hiding this comment.
maybe rename to LastError to avoid confusion with error interface
dtjm
reviewed
Apr 12, 2017
|
|
||
| // Errors returns all errors from internal buffer | ||
| func (cb *Breaker) Errors() (errors []error) { | ||
| cb.errorsBuffer.Do(func(x interface{}) { |
There was a problem hiding this comment.
This will output the current error and then the rest.
errors ordered as 1 2 3 will be output as 3 1 2
dtjm
reviewed
Apr 12, 2017
| func (cb *Breaker) Errors() (errors []error) { | ||
| cb.errorsBuffer.Do(func(x interface{}) { | ||
| if x != nil { | ||
| errors = append(errors, x.(error)) |
There was a problem hiding this comment.
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
dtjm
reviewed
Apr 12, 2017
|
|
||
| state := cb.state() | ||
| if state == halfopen { | ||
| if state == halfopen || state == open { |
dtjm
reviewed
Apr 12, 2017
| if errs[1].Error() != "circuit error" { | ||
| t.Fatalf("expected `%s` error, got %s", "circuit error", errs[0].Error()) | ||
| } | ||
| } |
…unreliable timeout test
|
Add test for race? |
|
@rubyist can this be merged? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…unreliable timeout test
Fixes #45