Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable parallel testing #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 30 additions & 0 deletions httpclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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" }`
Expand Down Expand Up @@ -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) {
Expand All @@ -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" }`
Expand Down Expand Up @@ -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" }`
Expand Down Expand Up @@ -257,6 +269,8 @@ func BenchmarkHTTPClientGetRetriesOnFailure(b *testing.B) {
}

func TestHTTPClientPostRetriesOnFailure(t *testing.T) {
t.Parallel()

count := 0
noOfRetries := 3
noOfCalls := noOfRetries + 1
Expand Down Expand Up @@ -312,6 +326,8 @@ func BenchmarkHTTPClientPostRetriesOnFailure(b *testing.B) {
}

func TestHTTPClientGetReturnsNoErrorsIfRetriesFailWith5xx(t *testing.T) {
t.Parallel()

count := 0
noOfRetries := 2
backoffInterval := 1 * time.Millisecond
Expand Down Expand Up @@ -341,6 +357,8 @@ func TestHTTPClientGetReturnsNoErrorsIfRetriesFailWith5xx(t *testing.T) {
}

func TestHTTPClientGetReturnsNoErrorsIfRetrySucceeds(t *testing.T) {
t.Parallel()

count := 0
countWhenCallSucceeds := 2
backoffInterval := 1 * time.Millisecond
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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{})
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand Down
28 changes: 28 additions & 0 deletions hystrix/hystrix_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -258,6 +268,8 @@ func TestHystrixHTTPClientPatchSuccess(t *testing.T) {
}

func TestHystrixHTTPClientRetriesGetOnFailure(t *testing.T) {
t.Parallel()

backoffInterval := 1 * time.Millisecond
maximumJitterInterval := 1 * time.Millisecond

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"),
Expand All @@ -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"),
Expand All @@ -443,6 +463,8 @@ func TestHystrixHTTPClientReturnsFallbackFailureWithAFallBackFunctionWhichReturn
}

func TestFallBackFunctionIsCalledWithHystrixHTTPClient(t *testing.T) {
t.Parallel()

called := false

client := NewClient(
Expand All @@ -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"),
Expand All @@ -485,6 +509,8 @@ func TestHystrixHTTPClientReturnsFallbackFailureWithAFallBackFunctionWhichReturn
}

func TestCustomHystrixHTTPClientDoSuccess(t *testing.T) {
t.Parallel()

client := NewClient(
WithHTTPTimeout(10*time.Millisecond),
WithCommandName("some_new_command_name"),
Expand Down Expand Up @@ -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)
Expand Down