46 lines
988 B
Go
Raw Normal View History

2016-03-15 18:38:16 +00:00
package hystrix
import (
"testing"
2016-03-15 18:45:59 +00:00
"github.com/afex/hystrix-go/hystrix"
2016-03-15 18:38:16 +00:00
"github.com/micro/go-micro/client"
2019-06-21 15:24:15 +01:00
"github.com/micro/go-micro/client/selector"
2019-06-27 09:49:39 +01:00
"github.com/micro/go-micro/registry/memory"
2016-03-15 18:38:16 +00:00
2018-03-03 12:28:44 +00:00
"context"
2016-03-15 18:38:16 +00:00
)
func TestBreaker(t *testing.T) {
// setup
2019-01-14 15:30:33 +00:00
r := memory.NewRegistry()
2016-03-15 18:38:16 +00:00
s := selector.NewSelector(selector.Registry(r))
c := client.NewClient(
// set the selector
client.Selector(s),
// add the breaker wrapper
client.Wrap(NewClientWrapper()),
)
2018-04-17 11:26:18 +01:00
req := c.NewRequest("test.service", "Test.Method", map[string]string{
2016-03-15 18:38:16 +00:00
"foo": "bar",
2018-04-17 11:26:18 +01:00
}, client.WithContentType("application/json"))
2016-03-15 18:38:16 +00:00
var rsp map[string]interface{}
// Force to point of trip
2017-01-09 14:50:28 +00:00
for i := 0; i < (hystrix.DefaultVolumeThreshold * 3); i++ {
2016-03-15 18:38:16 +00: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 18:45:59 +00:00
t.Errorf("Expecting tripped breaker, got %v", err)
2016-03-15 18:38:16 +00:00
}
}