circuitbreaker
circuitbreaker copied to clipboard
circuit function calls 1 time and not tripped
var count int
cb := circuit.NewThresholdBreaker(3)
//circuit function should be call 3 times
err := cb.Call(func() error {
count += 1
_, err := rpc.DialHTTP("tcp", "127.0.0.1:4000") //connection error occurred
return err //err not nil
}, 0)
fmt.Printf("called %d times tripped: %t err:%v\n", count, cb.Tripped(), err)
Output: called 1 times tripped: false err:dial tcp 127.0.0.1:4000: connection refused
The code sets up a new threshold breaker configured to trip after 3 unsuccessful calls. The code above only calls,and fails, once. The circuit breaker still has 2 remaining unsuccessful calls to go before tripping. So the last line prints that the circuit isn't tripped after 1 call. I'd say this is expected behavior.
Change the example to fail 2 more times and then print the state again. It should be tripped at that point.