Skip to content

Commit 4581e51

Browse files
committed
refactor initialization of structures in internal/backoff
1 parent 62a8dfc commit 4581e51

File tree

3 files changed

+40
-34
lines changed

3 files changed

+40
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Added explicit initialization of all fields of the `logBackoff` structure in `internal/backoff/backoff.go`, when golangci-lint exhaustruct enabled
12
* Added explicit initialization of fields of structures in `internal/allocator/allocator.go`, when golangci-lint exhaustruct enabled
23
* Added explicit initialization of all fields of the `endpoint` structure in `internal/endpoint/endpoint.go`, when golangci-lint exhaustruct enabled
34

internal/backoff/backoff.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ func WithSeed(seed int64) option {
8484

8585
func New(opts ...option) logBackoff {
8686
b := logBackoff{
87-
r: xrand.New(xrand.WithLock()),
87+
slotDuration: time.Duration(0),
88+
ceiling: 0,
89+
jitterLimit: 0,
90+
r: xrand.New(xrand.WithLock()),
8891
}
8992
for _, o := range opts {
9093
if o != nil {

internal/backoff/backoff_test.go

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ func TestLogBackoff(t *testing.T) {
6060
WithSeed(0),
6161
),
6262
exp: []exp{
63-
{gte: 0, lte: time.Second},
64-
{gte: 0, lte: 2 * time.Second},
65-
{gte: 0, lte: 4 * time.Second},
66-
{gte: 0, lte: 8 * time.Second},
67-
{gte: 0, lte: 8 * time.Second},
68-
{gte: 0, lte: 8 * time.Second},
69-
{gte: 0, lte: 8 * time.Second},
63+
{eq: 0, gte: 0, lte: time.Second},
64+
{eq: 0, gte: 0, lte: 2 * time.Second},
65+
{eq: 0, gte: 0, lte: 4 * time.Second},
66+
{eq: 0, gte: 0, lte: 8 * time.Second},
67+
{eq: 0, gte: 0, lte: 8 * time.Second},
68+
{eq: 0, gte: 0, lte: 8 * time.Second},
69+
{eq: 0, gte: 0, lte: 8 * time.Second},
7070
},
7171
seeds: 1000,
7272
},
@@ -78,13 +78,13 @@ func TestLogBackoff(t *testing.T) {
7878
WithSeed(0),
7979
),
8080
exp: []exp{
81-
{gte: 500 * time.Millisecond, lte: time.Second},
82-
{gte: 1 * time.Second, lte: 2 * time.Second},
83-
{gte: 2 * time.Second, lte: 4 * time.Second},
84-
{gte: 4 * time.Second, lte: 8 * time.Second},
85-
{gte: 4 * time.Second, lte: 8 * time.Second},
86-
{gte: 4 * time.Second, lte: 8 * time.Second},
87-
{gte: 4 * time.Second, lte: 8 * time.Second},
81+
{eq: 0, gte: 500 * time.Millisecond, lte: time.Second},
82+
{eq: 0, gte: 1 * time.Second, lte: 2 * time.Second},
83+
{eq: 0, gte: 2 * time.Second, lte: 4 * time.Second},
84+
{eq: 0, gte: 4 * time.Second, lte: 8 * time.Second},
85+
{eq: 0, gte: 4 * time.Second, lte: 8 * time.Second},
86+
{eq: 0, gte: 4 * time.Second, lte: 8 * time.Second},
87+
{eq: 0, gte: 4 * time.Second, lte: 8 * time.Second},
8888
},
8989
seeds: 1000,
9090
},
@@ -96,14 +96,15 @@ func TestLogBackoff(t *testing.T) {
9696
WithSeed(0),
9797
),
9898
exp: []exp{
99-
{eq: time.Second},
100-
{eq: 2 * time.Second},
101-
{eq: 4 * time.Second},
102-
{eq: 8 * time.Second},
103-
{eq: 8 * time.Second},
104-
{eq: 8 * time.Second},
105-
{eq: 8 * time.Second},
99+
{eq: time.Second, gte: 0, lte: 0},
100+
{eq: 2 * time.Second, gte: 0, lte: 0},
101+
{eq: 4 * time.Second, gte: 0, lte: 0},
102+
{eq: 8 * time.Second, gte: 0, lte: 0},
103+
{eq: 8 * time.Second, gte: 0, lte: 0},
104+
{eq: 8 * time.Second, gte: 0, lte: 0},
105+
{eq: 8 * time.Second, gte: 0, lte: 0},
106106
},
107+
seeds: 0,
107108
},
108109
{
109110
backoff: New(
@@ -113,19 +114,20 @@ func TestLogBackoff(t *testing.T) {
113114
WithSeed(0),
114115
),
115116
exp: []exp{
116-
{eq: time.Second},
117-
{eq: 2 * time.Second},
118-
{eq: 4 * time.Second},
119-
{eq: 8 * time.Second},
120-
{eq: 16 * time.Second},
121-
{eq: 32 * time.Second},
122-
{eq: 64 * time.Second},
123-
{eq: 64 * time.Second},
124-
{eq: 64 * time.Second},
125-
{eq: 64 * time.Second},
126-
{eq: 64 * time.Second},
127-
{eq: 64 * time.Second},
117+
{eq: time.Second, gte: 0, lte: 0},
118+
{eq: 2 * time.Second, gte: 0, lte: 0},
119+
{eq: 4 * time.Second, gte: 0, lte: 0},
120+
{eq: 8 * time.Second, gte: 0, lte: 0},
121+
{eq: 16 * time.Second, gte: 0, lte: 0},
122+
{eq: 32 * time.Second, gte: 0, lte: 0},
123+
{eq: 64 * time.Second, gte: 0, lte: 0},
124+
{eq: 64 * time.Second, gte: 0, lte: 0},
125+
{eq: 64 * time.Second, gte: 0, lte: 0},
126+
{eq: 64 * time.Second, gte: 0, lte: 0},
127+
{eq: 64 * time.Second, gte: 0, lte: 0},
128+
{eq: 64 * time.Second, gte: 0, lte: 0},
128129
},
130+
seeds: 0,
129131
},
130132
} {
131133
t.Run("", func(t *testing.T) {

0 commit comments

Comments
 (0)