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

Breaker.Ready() has side effects #33

Open
youngkin opened this issue Apr 17, 2016 · 0 comments
Open

Breaker.Ready() has side effects #33

youngkin opened this issue Apr 17, 2016 · 0 comments

Comments

@youngkin
Copy link

youngkin commented Apr 17, 2016

Calling Ready() on a half-open breaker will reset the breaker to open. I'm writing a test to better understand how Breaker behaves in a half-open state. I'm using Breaker.Ready() to detect when the Breaker transitions to half-open.

...
// Breaker trips to open
...

ready := cb.Ready()
fmt.Print("\nLet circuit transition to half-open\n\n")
for {
    if ready {
        break
    }
    time.Sleep(10 * time.Millisecond)
    ready = cb.Ready()
}

fmt.Printf("\nReady() == %v; Tripped == %v\n", ready, cb.Tripped())
fmt.Printf("Call Ready() again after it returns true, Ready() == %v; Tripped() == %v\n\n", 
               cb.Ready(), cb.Tripped())

When run it prints

Ready() == true; Tripped == true
Call Ready() again after it returns true, Ready() == false; Tripped() == true

Since Call() also invokes Ready(), using Ready() as I did above causes the subsequent call to Call() to fail since the circuit state is now open.

So, is there a way to test a Breaker to see if it's half-open without calling Ready()? Also, given Ready()'s side effects, perhaps it shouldn't be public?

UPDATE: After re-reading the README file I have a better understanding of the intended use of Ready() to allow the user to implement their own version of Call(). Even so, it would be nice to call out in the godoc that Ready() should not be used in conjunction with Call().

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

No branches or pull requests

1 participant