88)
99
1010func 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
1921func 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
2832func 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
3440func 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
4048func 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
4656func 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
5365func 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
6074func 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
6783func 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
7694func 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
85105func 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
91113func 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
98122func 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
105131func 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 )
0 commit comments