From 6b1c086d1c0602c42294087f23cae6a9081e7f93 Mon Sep 17 00:00:00 2001 From: Edward Date: Fri, 8 May 2020 16:45:03 +0800 Subject: [PATCH] fix testing for sony's breaker testing --- .../gobreaker/gobreaker_example_test.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/gomore/06_circuit_breaker/gobreaker/gobreaker_example_test.go b/gomore/06_circuit_breaker/gobreaker/gobreaker_example_test.go index e85ac49..e2da2b1 100644 --- a/gomore/06_circuit_breaker/gobreaker/gobreaker_example_test.go +++ b/gomore/06_circuit_breaker/gobreaker/gobreaker_example_test.go @@ -3,16 +3,19 @@ package gobreaker import ( "fmt" "io/ioutil" - "log" "net/http" + "testing" ) -var cb *gobreaker.CircuitBreaker +var cb *CircuitBreaker func TestGoBreaker(t *testing.T) { - body, err := Get("http://www.google.com/robots.txt") + + initBreaker() + + body, err := Get("https://bing.com/robots.txt") if err != nil { t.Fatal(err) } @@ -22,14 +25,14 @@ func TestGoBreaker(t *testing.T) { func initBreaker() { - var st gobreaker.Settings + var st Settings st.Name = "HTTP GET" - st.ReadyToTrip = func(counts gobreaker.Counts) bool { + st.ReadyToTrip = func(counts Counts) bool { failureRatio := float64(counts.TotalFailures) / float64(counts.Requests) return counts.Requests >= 3 && failureRatio >= 0.6 } - cb = gobreaker.NewCircuitBreaker(st) + cb = NewCircuitBreaker(st) } // Get wraps http.Get in CircuitBreaker. @@ -53,5 +56,5 @@ func Get(url string) ([]byte, error) { } return body.([]byte), nil -} +}