rubyist / circuitbreaker

Circuit Breakers in Go
MIT License
1.12k stars 108 forks source link

circuit function calls 1 time and not tripped #23

Open grr89 opened 9 years ago

grr89 commented 9 years ago
    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

youngkin commented 8 years ago

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.