func TestHystrixHTTPClientGetReturnedURLTimeout(t *testing.T) {
client := NewClient(
WithHTTPTimeout(5*time.Millisecond),
WithCommandName("some_command_name"),
WithHystrixTimeout(20*time.Millisecond),
WithMaxConcurrentRequests(2000),
WithErrorPercentThreshold(10),
WithSleepWindow(100),
WithRequestVolumeThreshold(10000),
)
dummyHandler := func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method)
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
assert.Equal(t, "en", r.Header.Get("Accept-Language"))
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`{ "response": "ok" }`))
time.Sleep(10 * time.Millisecond)
}
server := httptest.NewServer(http.HandlerFunc(dummyHandler))
defer server.Close()
headers := http.Header{}
headers.Set("Content-Type", "application/json")
headers.Set("Accept-Language", "en")
wg := sync.WaitGroup{}
for n := 0; n < 100; n++ {
wg.Add(1)
go func() {
defer wg.Done()
_, err := client.Get(server.URL, headers)
require.Error(t, err, "should having Client.Timeout exceeded while awaiting headers error")
assert.IsType(t, &url.Error{}, err)
}()
}
wg.Wait()
}
WARNING: DATA RACE
Write at 0x00c00020a5c0 by goroutine 99:
github.com/gojektech/heimdall/hystrix.(*Client).Do()
/Users/ardhi/gopath/src/github.com/gojektech/heimdall/hystrix/hystrix_client.go:181 +0x3e1
github.com/gojektech/heimdall/hystrix.(*Client).Get()
/Users/ardhi/gopath/src/github.com/gojektech/heimdall/hystrix/hystrix_client.go:105 +0xca
github.com/gojektech/heimdall/hystrix.TestHystrixHTTPClientGetReturnedURLTimeout.func2()
/Users/ardhi/gopath/src/github.com/gojektech/heimdall/hystrix/hystrix_client_test.go:566 +0xab
Previous write at 0x00c00020a5c0 by goroutine 138:
github.com/gojektech/heimdall/hystrix.(*Client).Do.func1()
/Users/ardhi/gopath/src/github.com/gojektech/heimdall/hystrix/hystrix_client.go:182 +0xe4
github.com/afex/hystrix-go/hystrix.Do.func1()
/Users/ardhi/gopath/src/github.com/afex/hystrix-go/hystrix/hystrix.go:179 +0x4a
github.com/afex/hystrix-go/hystrix.Go.func3()
/Users/ardhi/gopath/src/github.com/afex/hystrix-go/hystrix/hystrix.go:140 +0x1d3
Goroutine 99 (running) created at:
github.com/gojektech/heimdall/hystrix.TestHystrixHTTPClientGetReturnedURLTimeout()
/Users/ardhi/gopath/src/github.com/gojektech/heimdall/hystrix/hystrix_client_test.go:564 +0x370
testing.tRunner()
/usr/local/Cellar/go/1.11.5/libexec/src/testing/testing.go:827 +0x162
Goroutine 138 (running) created at:
github.com/afex/hystrix-go/hystrix.Go()
/Users/ardhi/gopath/src/github.com/afex/hystrix-go/hystrix/hystrix.go:96 +0x551
github.com/afex/hystrix-go/hystrix.Do()
/Users/ardhi/gopath/src/github.com/afex/hystrix-go/hystrix/hystrix.go:200 +0x32d
github.com/gojektech/heimdall/hystrix.(*Client).Do()
/Users/ardhi/gopath/src/github.com/gojektech/heimdall/hystrix/hystrix_client.go:181 +0x3b9
github.com/gojektech/heimdall/hystrix.(*Client).Get()
/Users/ardhi/gopath/src/github.com/gojektech/heimdall/hystrix/hystrix_client.go:105 +0xca
github.com/gojektech/heimdall/hystrix.TestHystrixHTTPClientGetReturnedURLTimeout.func2()
/Users/ardhi/gopath/src/github.com/gojektech/heimdall/hystrix/hystrix_client_test.go:566 +0xab