Package list golang-github-go-kit-kit / de552e08-1950-4c1b-983e-dd11d2b704d4/main circuitbreaker / handy_breaker_test.go
de552e08-1950-4c1b-983e-dd11d2b704d4/main

Tree @de552e08-1950-4c1b-983e-dd11d2b704d4/main (Download .tar.gz)

handy_breaker_test.go @de552e08-1950-4c1b-983e-dd11d2b704d4/mainraw · history · blame

package circuitbreaker_test

import (
	"testing"

	handybreaker "github.com/streadway/handy/breaker"

	"github.com/go-kit/kit/circuitbreaker"
)

func TestHandyBreaker(t *testing.T) {
	var (
		failureRatio     = 0.05
		breaker          = circuitbreaker.HandyBreaker(handybreaker.NewBreaker(failureRatio))
		primeWith        = handybreaker.DefaultMinObservations * 10
		shouldPass       = func(n int) bool { return (float64(n) / float64(primeWith+n)) <= failureRatio }
		openCircuitError = handybreaker.ErrCircuitOpen.Error()
	)
	testFailingEndpoint(t, breaker, primeWith, shouldPass, 0, openCircuitError)
}