mirror of
https://github.com/crazybber/go-pattern-examples.git
synced 2024-11-22 11:56:03 +03:00
fix testing for sony's breaker testing
This commit is contained in:
parent
3e50d054e2
commit
6b1c086d1c
@ -3,16 +3,19 @@ package gobreaker
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var cb *gobreaker.CircuitBreaker
|
var cb *CircuitBreaker
|
||||||
|
|
||||||
|
|
||||||
func TestGoBreaker(t *testing.T) {
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -22,14 +25,14 @@ func TestGoBreaker(t *testing.T) {
|
|||||||
|
|
||||||
|
|
||||||
func initBreaker() {
|
func initBreaker() {
|
||||||
var st gobreaker.Settings
|
var st Settings
|
||||||
st.Name = "HTTP GET"
|
st.Name = "HTTP GET"
|
||||||
st.ReadyToTrip = func(counts gobreaker.Counts) bool {
|
st.ReadyToTrip = func(counts Counts) bool {
|
||||||
failureRatio := float64(counts.TotalFailures) / float64(counts.Requests)
|
failureRatio := float64(counts.TotalFailures) / float64(counts.Requests)
|
||||||
return counts.Requests >= 3 && failureRatio >= 0.6
|
return counts.Requests >= 3 && failureRatio >= 0.6
|
||||||
}
|
}
|
||||||
|
|
||||||
cb = gobreaker.NewCircuitBreaker(st)
|
cb = NewCircuitBreaker(st)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get wraps http.Get in CircuitBreaker.
|
// Get wraps http.Get in CircuitBreaker.
|
||||||
@ -53,5 +56,5 @@ func Get(url string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return body.([]byte), nil
|
return body.([]byte), nil
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user