Package list golang-github-go-kit-kit / 93fed9e2-784b-413e-a591-aaae2048677d/main circuitbreaker / handy_breaker_test.go
93fed9e2-784b-413e-a591-aaae2048677d/main

Tree @93fed9e2-784b-413e-a591-aaae2048677d/main (Download .tar.gz)

handy_breaker_test.go @93fed9e2-784b-413e-a591-aaae2048677d/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)
}