@@ -2,14 +2,21 @@ package circuitbreaker_test
22
33import (
44 "errors"
5+ "fmt"
6+ "path/filepath"
7+ "runtime"
58 "testing"
9+ "time"
610
711 "golang.org/x/net/context"
812
913 "github.com/go-kit/kit/endpoint"
1014)
1115
1216func testFailingEndpoint (t * testing.T , breaker endpoint.Middleware , primeWith int , shouldPass func (int ) bool , openCircuitError string ) {
17+ _ , file , line , _ := runtime .Caller (1 )
18+ caller := fmt .Sprintf ("%s:%d" , filepath .Base (file ), line )
19+
1320 // Create a mock endpoint and wrap it with the breaker.
1421 m := mock {}
1522 var e endpoint.Endpoint
@@ -19,7 +26,7 @@ func testFailingEndpoint(t *testing.T, breaker endpoint.Middleware, primeWith in
1926 // Prime the endpoint with successful requests.
2027 for i := 0 ; i < primeWith ; i ++ {
2128 if _ , err := e (context .Background (), struct {}{}); err != nil {
22- t .Fatalf ("during priming, got error: %v" , err )
29+ t .Fatalf ("%s: during priming, got error: %v" , caller , err )
2330 }
2431 }
2532
@@ -30,21 +37,24 @@ func testFailingEndpoint(t *testing.T, breaker endpoint.Middleware, primeWith in
3037 // The first several should be allowed through and yield our error.
3138 for i := 0 ; shouldPass (i ); i ++ {
3239 if _ , err := e (context .Background (), struct {}{}); err != m .err {
33- t .Fatalf ("want %v, have %v" , m .err , err )
40+ t .Fatalf ("%s: want %v, have %v" , caller , m .err , err )
3441 }
3542 }
3643 thru := m .thru
3744
45+ // https://github.com/afex/hystrix-go/issues/41
46+ time .Sleep (time .Millisecond )
47+
3848 // But the rest should be blocked by an open circuit.
3949 for i := 0 ; i < 10 ; i ++ {
4050 if _ , err := e (context .Background (), struct {}{}); err .Error () != openCircuitError {
41- t .Fatalf ("want %q, have %q" , openCircuitError , err .Error ())
51+ t .Fatalf ("%s: want %q, have %q" , caller , openCircuitError , err .Error ())
4252 }
4353 }
4454
4555 // Make sure none of those got through.
4656 if want , have := thru , m .thru ; want != have {
47- t .Errorf ("want %d, have %d" , want , have )
57+ t .Errorf ("%s: want %d, have %d" , caller , want , have )
4858 }
4959}
5060
0 commit comments