circuitbreaker icon indicating copy to clipboard operation
circuitbreaker copied to clipboard

circuit function calls 1 time and not tripped

Open grr89 opened this issue 9 years ago • 1 comments

    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

grr89 avatar Apr 22 '15 07:04 grr89

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.

youngkin avatar Apr 17 '16 15:04 youngkin