micro-wrapper-breaker-hystrix/hystrix_test.go

46 lines
954 B
Go
Raw Normal View History

2016-03-15 21:38:16 +03:00
package hystrix
import (
"testing"
2016-03-15 21:45:59 +03:00
"github.com/afex/hystrix-go/hystrix"
2016-03-15 21:38:16 +03:00
"github.com/micro/go-micro/client"
"github.com/micro/go-micro/registry/mock"
"github.com/micro/go-micro/selector"
"golang.org/x/net/context"
)
func TestBreaker(t *testing.T) {
// setup
r := mock.NewRegistry()
s := selector.NewSelector(selector.Registry(r))
c := client.NewClient(
// set the selector
client.Selector(s),
// add the breaker wrapper
client.Wrap(NewClientWrapper()),
)
req := c.NewJsonRequest("test.service", "Test.Method", map[string]string{
"foo": "bar",
})
var rsp map[string]interface{}
// Force to point of trip
2017-01-09 17:50:28 +03:00
for i := 0; i < (hystrix.DefaultVolumeThreshold * 3); i++ {
2016-03-15 21:38:16 +03:00
c.Call(context.TODO(), req, rsp)
}
err := c.Call(context.TODO(), req, rsp)
if err == nil {
t.Error("Expecting tripped breaker, got nil error")
}
if err.Error() != "hystrix: circuit open" {
2016-03-15 21:45:59 +03:00
t.Errorf("Expecting tripped breaker, got %v", err)
2016-03-15 21:38:16 +03:00
}
}