diff --git a/Makefile b/Makefile index e7fb1b2..34f202b 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,6 @@ test-cover-html: @echo "mode: count" > coverage-all.out $(foreach pkg, $(ALL_PACKAGES),\ - ENVIRONMENT=test go test -coverprofile=coverage.out -covermode=count $(pkg);\ - tail -n +2 coverage.out >> coverage-all.out;) + ENVIRONMENT=test go test -race -coverprofile=coverage.out -covermode=count $(pkg);\ + tail -n +2 coverage.out >> coverage-all.out;) go tool cover -html=coverage-all.out -o out/coverage.html diff --git a/httpclient/client_test.go b/httpclient/client_test.go index dbca35d..91bd98e 100644 --- a/httpclient/client_test.go +++ b/httpclient/client_test.go @@ -16,6 +16,8 @@ import ( ) func TestHTTPClientDoSuccess(t *testing.T) { + t.Parallel() + client := NewClient(WithHTTPTimeout(10 * time.Millisecond)) dummyHandler := func(w http.ResponseWriter, r *http.Request) { @@ -45,6 +47,8 @@ func TestHTTPClientDoSuccess(t *testing.T) { } func TestHTTPClientGetSuccess(t *testing.T) { + t.Parallel() + client := NewClient(WithHTTPTimeout(10 * time.Millisecond)) dummyHandler := func(w http.ResponseWriter, r *http.Request) { @@ -71,6 +75,8 @@ func TestHTTPClientGetSuccess(t *testing.T) { } func TestHTTPClientPostSuccess(t *testing.T) { + t.Parallel() + client := NewClient(WithHTTPTimeout(10 * time.Millisecond)) requestBodyString := `{ "name": "heimdall" }` @@ -106,6 +112,8 @@ func TestHTTPClientPostSuccess(t *testing.T) { } func TestHTTPClientDeleteSuccess(t *testing.T) { + t.Parallel() + client := NewClient(WithHTTPTimeout(10 * time.Millisecond)) dummyHandler := func(w http.ResponseWriter, r *http.Request) { @@ -132,6 +140,8 @@ func TestHTTPClientDeleteSuccess(t *testing.T) { } func TestHTTPClientPutSuccess(t *testing.T) { + t.Parallel() + client := NewClient(WithHTTPTimeout(10 * time.Millisecond)) requestBodyString := `{ "name": "heimdall" }` @@ -167,6 +177,8 @@ func TestHTTPClientPutSuccess(t *testing.T) { } func TestHTTPClientPatchSuccess(t *testing.T) { + t.Parallel() + client := NewClient(WithHTTPTimeout(10 * time.Millisecond)) requestBodyString := `{ "name": "heimdall" }` @@ -257,6 +269,8 @@ func BenchmarkHTTPClientGetRetriesOnFailure(b *testing.B) { } func TestHTTPClientPostRetriesOnFailure(t *testing.T) { + t.Parallel() + count := 0 noOfRetries := 3 noOfCalls := noOfRetries + 1 @@ -312,6 +326,8 @@ func BenchmarkHTTPClientPostRetriesOnFailure(b *testing.B) { } func TestHTTPClientGetReturnsNoErrorsIfRetriesFailWith5xx(t *testing.T) { + t.Parallel() + count := 0 noOfRetries := 2 backoffInterval := 1 * time.Millisecond @@ -341,6 +357,8 @@ func TestHTTPClientGetReturnsNoErrorsIfRetriesFailWith5xx(t *testing.T) { } func TestHTTPClientGetReturnsNoErrorsIfRetrySucceeds(t *testing.T) { + t.Parallel() + count := 0 countWhenCallSucceeds := 2 backoffInterval := 1 * time.Millisecond @@ -374,6 +392,8 @@ func TestHTTPClientGetReturnsNoErrorsIfRetrySucceeds(t *testing.T) { } func TestHTTPClientGetReturnsErrorOnClientCallFailure(t *testing.T) { + t.Parallel() + client := NewClient(WithHTTPTimeout(10 * time.Millisecond)) dummyHandler := func(w http.ResponseWriter, r *http.Request) { @@ -393,6 +413,8 @@ func TestHTTPClientGetReturnsErrorOnClientCallFailure(t *testing.T) { } func TestHTTPClientGetReturnsNoErrorOn5xxFailure(t *testing.T) { + t.Parallel() + client := NewClient(WithHTTPTimeout(10 * time.Millisecond)) dummyHandler := func(w http.ResponseWriter, r *http.Request) { @@ -410,6 +432,8 @@ func TestHTTPClientGetReturnsNoErrorOn5xxFailure(t *testing.T) { } func TestHTTPClientGetReturnsErrorOnFailure(t *testing.T) { + t.Parallel() + client := NewClient(WithHTTPTimeout(10 * time.Millisecond)) response, err := client.Get("url_doenst_exist", http.Header{}) @@ -418,6 +442,8 @@ func TestHTTPClientGetReturnsErrorOnFailure(t *testing.T) { } func TestPluginMethodsCalled(t *testing.T) { + t.Parallel() + client := NewClient(WithHTTPTimeout(10 * time.Millisecond)) mockPlugin := &MockPlugin{} client.AddPlugin(mockPlugin) @@ -449,6 +475,8 @@ func TestPluginMethodsCalled(t *testing.T) { } func TestPluginErrorMethodCalled(t *testing.T) { + t.Parallel() + client := NewClient(WithHTTPTimeout(10 * time.Millisecond)) mockPlugin := &MockPlugin{} client.AddPlugin(mockPlugin) @@ -481,6 +509,8 @@ func (c *myHTTPClient) Do(request *http.Request) (*http.Response, error) { } func TestCustomHTTPClientHeaderSuccess(t *testing.T) { + t.Parallel() + client := NewClient( WithHTTPTimeout(10*time.Millisecond), WithHTTPClient(&myHTTPClient{ diff --git a/hystrix/hystrix_client_test.go b/hystrix/hystrix_client_test.go index 65a7bbd..cb2e970 100644 --- a/hystrix/hystrix_client_test.go +++ b/hystrix/hystrix_client_test.go @@ -24,6 +24,8 @@ func (c *myHTTPClient) Do(request *http.Request) (*http.Response, error) { } func TestHystrixHTTPClientDoSuccess(t *testing.T) { + t.Parallel() + client := NewClient( WithHTTPTimeout(50*time.Millisecond), WithCommandName("some_command_name"), @@ -61,6 +63,8 @@ func TestHystrixHTTPClientDoSuccess(t *testing.T) { } func TestHystrixHTTPClientGetSuccess(t *testing.T) { + t.Parallel() + client := NewClient( WithHTTPTimeout(10*time.Millisecond), WithCommandName("some_command_name"), @@ -95,6 +99,8 @@ func TestHystrixHTTPClientGetSuccess(t *testing.T) { } func TestHystrixHTTPClientPostSuccess(t *testing.T) { + t.Parallel() + client := NewClient( WithHTTPTimeout(10*time.Millisecond), WithCommandName("some_command_name"), @@ -138,6 +144,8 @@ func TestHystrixHTTPClientPostSuccess(t *testing.T) { } func TestHystrixHTTPClientDeleteSuccess(t *testing.T) { + t.Parallel() + client := NewClient( WithHTTPTimeout(10*time.Millisecond), WithCommandName("some_command_name"), @@ -215,6 +223,8 @@ func TestHystrixHTTPClientPutSuccess(t *testing.T) { } func TestHystrixHTTPClientPatchSuccess(t *testing.T) { + t.Parallel() + client := NewClient( WithHTTPTimeout(10*time.Millisecond), WithCommandName("some_command_name"), @@ -258,6 +268,8 @@ func TestHystrixHTTPClientPatchSuccess(t *testing.T) { } func TestHystrixHTTPClientRetriesGetOnFailure(t *testing.T) { + t.Parallel() + backoffInterval := 1 * time.Millisecond maximumJitterInterval := 1 * time.Millisecond @@ -280,6 +292,8 @@ func TestHystrixHTTPClientRetriesGetOnFailure(t *testing.T) { } func TestHystrixHTTPClientRetriesGetOnFailure5xx(t *testing.T) { + t.Parallel() + count := 0 backoffInterval := 1 * time.Millisecond maximumJitterInterval := 1 * time.Millisecond @@ -344,6 +358,8 @@ func BenchmarkHystrixHTTPClientRetriesGetOnFailure(b *testing.B) { } func TestHystrixHTTPClientRetriesPostOnFailure(t *testing.T) { + t.Parallel() + count := 0 backoffInterval := 1 * time.Millisecond maximumJitterInterval := 1 * time.Millisecond @@ -407,6 +423,8 @@ func BenchmarkHystrixHTTPClientRetriesPostOnFailure(b *testing.B) { } func TestHystrixHTTPClientReturnsFallbackFailureWithoutFallBackFunction(t *testing.T) { + t.Parallel() + client := NewClient( WithHTTPTimeout(10*time.Millisecond), WithCommandName("some_command_name"), @@ -422,6 +440,8 @@ func TestHystrixHTTPClientReturnsFallbackFailureWithoutFallBackFunction(t *testi } func TestHystrixHTTPClientReturnsFallbackFailureWithAFallBackFunctionWhichReturnAnError(t *testing.T) { + t.Parallel() + client := NewClient( WithHTTPTimeout(10*time.Millisecond), WithCommandName("some_command_name"), @@ -443,6 +463,8 @@ func TestHystrixHTTPClientReturnsFallbackFailureWithAFallBackFunctionWhichReturn } func TestFallBackFunctionIsCalledWithHystrixHTTPClient(t *testing.T) { + t.Parallel() + called := false client := NewClient( @@ -466,6 +488,8 @@ func TestFallBackFunctionIsCalledWithHystrixHTTPClient(t *testing.T) { } func TestHystrixHTTPClientReturnsFallbackFailureWithAFallBackFunctionWhichReturnsNil(t *testing.T) { + t.Parallel() + client := NewClient( WithHTTPTimeout(10*time.Millisecond), WithCommandName("some_command_name"), @@ -485,6 +509,8 @@ func TestHystrixHTTPClientReturnsFallbackFailureWithAFallBackFunctionWhichReturn } func TestCustomHystrixHTTPClientDoSuccess(t *testing.T) { + t.Parallel() + client := NewClient( WithHTTPTimeout(10*time.Millisecond), WithCommandName("some_new_command_name"), @@ -531,6 +557,8 @@ func respBody(t *testing.T, response *http.Response) string { } func TestDurationToInt(t *testing.T) { + t.Parallel() + t.Run("1sec should return 1 when unit is second", func(t *testing.T) { timeout := 1 * time.Second timeoutInSec := durationToInt(timeout, time.Second)