1 package circuitbreaker_test
9 "github.com/afex/hystrix-go/hystrix"
11 "github.com/go-kit/kit/circuitbreaker"
14 func TestHystrix(t *testing.T) {
15 stdlog.SetOutput(ioutil.Discard)
18 commandName = "my-endpoint"
22 hystrix.ConfigureCommand(commandName, hystrix.CommandConfig{
23 ErrorPercentThreshold: errorPercent,
24 MaxConcurrentRequests: maxConcurrent,
28 breaker = circuitbreaker.Hystrix(commandName)
29 primeWith = hystrix.DefaultVolumeThreshold * 2
30 shouldPass = func(n int) bool { return (float64(n) / float64(primeWith+n)) <= (float64(errorPercent-1) / 100.0) }
31 openCircuitError = hystrix.ErrCircuitOpen.Error()
34 // hystrix-go uses buffered channels to receive reports on request success/failure,
35 // and so is basically impossible to test deterministically. We have to make sure
36 // the report buffer is emptied, by injecting a sleep between each invocation.
37 requestDelay := 5 * time.Millisecond
39 testFailingEndpoint(t, breaker, primeWith, shouldPass, requestDelay, openCircuitError)