Skip to content

Commit a75486b

Browse files
committed
enable & fix paralleltest linter
1 parent 3d4ae0c commit a75486b

12 files changed

Lines changed: 125 additions & 22 deletions

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ linters:
99
- staticcheck
1010
- unused
1111
- modernize
12+
- paralleltest
1213
exclusions:
1314
generated: lax
1415
paths:

backoff_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
)
99

1010
func TestExponentialBackoffNextTime(t *testing.T) {
11+
t.Parallel()
12+
1113
exponentialBackoff := NewExponentialBackoff(100*time.Millisecond, 1000*time.Millisecond, 2.0, 0*time.Millisecond)
1214

1315
assert.Equal(t, 100*time.Millisecond, exponentialBackoff.Next(0))
@@ -17,6 +19,8 @@ func TestExponentialBackoffNextTime(t *testing.T) {
1719
}
1820

1921
func TestExponentialBackoffWithInvalidJitter(t *testing.T) {
22+
t.Parallel()
23+
2024
exponentialBackoff := NewExponentialBackoff(100*time.Millisecond, 1000*time.Millisecond, 2.0, -1*time.Millisecond)
2125

2226
assert.Equal(t, 100*time.Millisecond, exponentialBackoff.Next(0))
@@ -26,45 +30,59 @@ func TestExponentialBackoffWithInvalidJitter(t *testing.T) {
2630
}
2731

2832
func TestExponentialBackoffMaxTimeoutCrossed(t *testing.T) {
33+
t.Parallel()
34+
2935
exponentialBackoff := NewExponentialBackoff(100*time.Millisecond, 1000*time.Millisecond, 2.0, 0*time.Millisecond)
3036

3137
assert.Equal(t, 1000*time.Millisecond, exponentialBackoff.Next(4))
3238
}
3339

3440
func TestExponentialBackoffMaxTimeoutReached(t *testing.T) {
41+
t.Parallel()
42+
3543
exponentialBackoff := NewExponentialBackoff(100*time.Millisecond, 1600*time.Millisecond, 2.0, 0*time.Millisecond)
3644

3745
assert.Equal(t, 1600*time.Millisecond, exponentialBackoff.Next(4))
3846
}
3947

4048
func TestExponentialBackoffWhenRetryIsLessThanZero(t *testing.T) {
49+
t.Parallel()
50+
4151
exponentialBackoff := NewExponentialBackoff(100*time.Millisecond, 1000*time.Millisecond, 2.0, 0*time.Millisecond)
4252

4353
assert.Equal(t, 100*time.Millisecond, exponentialBackoff.Next(-1))
4454
}
4555

4656
func TestExponentialBackoffJitter0(t *testing.T) {
57+
t.Parallel()
58+
4759
exponentialBackoff := NewExponentialBackoff(100*time.Millisecond, 1000*time.Millisecond, 2.0, 0*time.Millisecond)
4860
for range 10000 {
4961
assert.Equal(t, 200*time.Millisecond, exponentialBackoff.Next(1))
5062
}
5163
}
5264

5365
func TestExponentialBackoffJitter1(t *testing.T) {
66+
t.Parallel()
67+
5468
exponentialBackoff := NewExponentialBackoff(100*time.Millisecond, 1000*time.Millisecond, 2.0, 1*time.Millisecond)
5569
for range 10000 {
5670
assert.True(t, 200*time.Millisecond <= exponentialBackoff.Next(1) && exponentialBackoff.Next(1) <= 201*time.Millisecond)
5771
}
5872
}
5973

6074
func TestExponentialBackoffJitter50(t *testing.T) {
75+
t.Parallel()
76+
6177
exponentialBackoff := NewExponentialBackoff(100*time.Millisecond, 1000*time.Millisecond, 2.0, 50*time.Millisecond)
6278
for range 10000 {
6379
assert.True(t, 200*time.Millisecond <= exponentialBackoff.Next(1) && exponentialBackoff.Next(1) <= 250*time.Millisecond)
6480
}
6581
}
6682

6783
func TestConstantBackoffNextTime(t *testing.T) {
84+
t.Parallel()
85+
6886
constantBackoff := NewConstantBackoff(100*time.Millisecond, 0*time.Millisecond)
6987

7088
assert.Equal(t, 100*time.Millisecond, constantBackoff.Next(0))
@@ -74,6 +92,8 @@ func TestConstantBackoffNextTime(t *testing.T) {
7492
}
7593

7694
func TestConstantBackoffWithInvalidJitter(t *testing.T) {
95+
t.Parallel()
96+
7797
constantBackoff := NewConstantBackoff(100*time.Millisecond, -1*time.Millisecond)
7898

7999
assert.Equal(t, 100*time.Millisecond, constantBackoff.Next(0))
@@ -83,26 +103,34 @@ func TestConstantBackoffWithInvalidJitter(t *testing.T) {
83103
}
84104

85105
func TestConstantBackoffWhenRetryIsLessThanZero(t *testing.T) {
106+
t.Parallel()
107+
86108
constantBackoff := NewConstantBackoff(100*time.Millisecond, 0*time.Millisecond)
87109

88110
assert.Equal(t, 100*time.Millisecond, constantBackoff.Next(-1))
89111
}
90112

91113
func TestConstantBackoffJitter0(t *testing.T) {
114+
t.Parallel()
115+
92116
constantBackoff := NewConstantBackoff(100*time.Millisecond, 0*time.Millisecond)
93117
for i := range 10000 {
94118
assert.Equal(t, 100*time.Millisecond, constantBackoff.Next(i))
95119
}
96120
}
97121

98122
func TestConstantBackoffJitter1(t *testing.T) {
123+
t.Parallel()
124+
99125
constantBackoff := NewConstantBackoff(100*time.Millisecond, 1*time.Millisecond)
100126
for i := range 10000 {
101127
assert.True(t, 100*time.Millisecond <= constantBackoff.Next(i) && constantBackoff.Next(1) <= 101*time.Millisecond)
102128
}
103129
}
104130

105131
func TestConstantBackoffJitter50(t *testing.T) {
132+
t.Parallel()
133+
106134
constantBackoff := NewConstantBackoff(100*time.Millisecond, 50*time.Millisecond)
107135
for i := range 10000 {
108136
assert.True(t, 100*time.Millisecond <= constantBackoff.Next(i) && constantBackoff.Next(1) <= 150*time.Millisecond)

httpclient/client_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ func TestHTTPClientPatchSuccess(t *testing.T) {
218218
}
219219

220220
func TestHTTPClientGetRetriesOnFailure(t *testing.T) {
221+
t.Parallel()
222+
221223
count := 0
222224
noOfRetries := 3
223225
noOfCalls := noOfRetries + 1
@@ -543,6 +545,8 @@ func TestCustomHTTPClientHeaderSuccess(t *testing.T) {
543545
}
544546

545547
func TestHTTPClientContextTimeout(t *testing.T) {
548+
t.Parallel()
549+
546550
client := NewClient(WithHTTPTimeout(1000 * time.Millisecond))
547551

548552
dummyHandler := func(w http.ResponseWriter, r *http.Request) {
@@ -584,6 +588,8 @@ func respBody(t *testing.T, response *http.Response) string {
584588
}
585589

586590
func TestHTTPClientDoContextCancelledDuringRetry(t *testing.T) {
591+
t.Parallel()
592+
587593
noOfRetries := 3
588594
backoffInterval := 100 * time.Millisecond
589595
maximumJitterInterval := 10 * time.Millisecond
@@ -622,6 +628,8 @@ func TestHTTPClientDoContextCancelledDuringRetry(t *testing.T) {
622628
}
623629

624630
func TestHTTPClientDoContextCancelledBeforeRetry(t *testing.T) {
631+
t.Parallel()
632+
625633
client := NewClient(
626634
WithHTTPTimeout(10*time.Millisecond),
627635
WithRetryCount(3),
@@ -654,6 +662,8 @@ func TestHTTPClientDoContextCancelledBeforeRetry(t *testing.T) {
654662
}
655663

656664
func TestHTTPClientDoContextTimeoutDuringRetry(t *testing.T) {
665+
t.Parallel()
666+
657667
noOfRetries := 3
658668
backoffInterval := 100 * time.Millisecond
659669
maximumJitterInterval := 10 * time.Millisecond
@@ -688,6 +698,8 @@ func TestHTTPClientDoContextTimeoutDuringRetry(t *testing.T) {
688698
}
689699

690700
func TestHTTPClientMultiRetryOnTimeout(t *testing.T) {
701+
t.Parallel()
702+
691703
noOfRetries := 3
692704
backoffInterval := 4 * time.Millisecond
693705
maximumJitterInterval := 2 * time.Millisecond

httpclient/options_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
)
1212

1313
func TestOptionsAreSet(t *testing.T) {
14+
t.Parallel()
15+
1416
backoffInterval := 1 * time.Millisecond
1517
maximumJitterInterval := 1 * time.Millisecond
1618
noOfRetries := 3
@@ -33,6 +35,8 @@ func TestOptionsAreSet(t *testing.T) {
3335
}
3436

3537
func TestOptionsHaveDefaults(t *testing.T) {
38+
t.Parallel()
39+
3640
retrier := heimdall.NewNoRetrier()
3741
httpTimeout := 30 * time.Second
3842
http.DefaultClient.Timeout = httpTimeout

hystrix/hystrix_client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,9 @@ func (hhc *Client) Do(request *http.Request) (*http.Response, error) {
223223
return response, nil
224224
}
225225

226-
func (hhc *Client) hystrixDo(request *http.Request) (response *http.Response, err error) {
227-
err = hystrix.DoC(request.Context(), hhc.hystrixCommandName, func(_ context.Context) error {
226+
func (hhc *Client) hystrixDo(request *http.Request) (*http.Response, error) {
227+
var response *http.Response
228+
err := hystrix.DoC(request.Context(), hhc.hystrixCommandName, func(_ context.Context) error {
228229
resp, doErr := hhc.client.Do(request)
229230
if doErr != nil {
230231
return doErr

0 commit comments

Comments
 (0)