Skip to content

Commit

Permalink
refactor initialization of 'logBackoff' structure
Browse files Browse the repository at this point in the history
  • Loading branch information
kozyrev-m committed Feb 10, 2024
1 parent 62a8dfc commit aca0292
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Added explicit initialization of all fields of the `logBackoff` structure in `internal/backoff/backoff.go`, when golangci-lint exhaustruct enabled
* Added explicit initialization of fields of structures in `internal/allocator/allocator.go`, when golangci-lint exhaustruct enabled
* Added explicit initialization of all fields of the `endpoint` structure in `internal/endpoint/endpoint.go`, when golangci-lint exhaustruct enabled

Expand Down
5 changes: 4 additions & 1 deletion internal/backoff/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ func WithSeed(seed int64) option {

func New(opts ...option) logBackoff {
b := logBackoff{
r: xrand.New(xrand.WithLock()),
slotDuration: time.Duration(0),
ceiling: 0,
jitterLimit: 0,
r: xrand.New(xrand.WithLock()),
}
for _, o := range opts {
if o != nil {
Expand Down
68 changes: 35 additions & 33 deletions internal/backoff/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ func TestLogBackoff(t *testing.T) {
WithSeed(0),
),
exp: []exp{
{gte: 0, lte: time.Second},
{gte: 0, lte: 2 * time.Second},
{gte: 0, lte: 4 * time.Second},
{gte: 0, lte: 8 * time.Second},
{gte: 0, lte: 8 * time.Second},
{gte: 0, lte: 8 * time.Second},
{gte: 0, lte: 8 * time.Second},
{eq: 0, gte: 0, lte: time.Second},
{eq: 0, gte: 0, lte: 2 * time.Second},
{eq: 0, gte: 0, lte: 4 * time.Second},
{eq: 0, gte: 0, lte: 8 * time.Second},
{eq: 0, gte: 0, lte: 8 * time.Second},
{eq: 0, gte: 0, lte: 8 * time.Second},
{eq: 0, gte: 0, lte: 8 * time.Second},
},
seeds: 1000,
},
Expand All @@ -78,13 +78,13 @@ func TestLogBackoff(t *testing.T) {
WithSeed(0),
),
exp: []exp{
{gte: 500 * time.Millisecond, lte: time.Second},
{gte: 1 * time.Second, lte: 2 * time.Second},
{gte: 2 * time.Second, lte: 4 * time.Second},
{gte: 4 * time.Second, lte: 8 * time.Second},
{gte: 4 * time.Second, lte: 8 * time.Second},
{gte: 4 * time.Second, lte: 8 * time.Second},
{gte: 4 * time.Second, lte: 8 * time.Second},
{eq: 0, gte: 500 * time.Millisecond, lte: time.Second},
{eq: 0, gte: 1 * time.Second, lte: 2 * time.Second},
{eq: 0, gte: 2 * time.Second, lte: 4 * time.Second},
{eq: 0, gte: 4 * time.Second, lte: 8 * time.Second},
{eq: 0, gte: 4 * time.Second, lte: 8 * time.Second},
{eq: 0, gte: 4 * time.Second, lte: 8 * time.Second},
{eq: 0, gte: 4 * time.Second, lte: 8 * time.Second},
},
seeds: 1000,
},
Expand All @@ -96,14 +96,15 @@ func TestLogBackoff(t *testing.T) {
WithSeed(0),
),
exp: []exp{
{eq: time.Second},
{eq: 2 * time.Second},
{eq: 4 * time.Second},
{eq: 8 * time.Second},
{eq: 8 * time.Second},
{eq: 8 * time.Second},
{eq: 8 * time.Second},
{eq: time.Second, gte: 0, lte: 0},
{eq: 2 * time.Second, gte: 0, lte: 0},
{eq: 4 * time.Second, gte: 0, lte: 0},
{eq: 8 * time.Second, gte: 0, lte: 0},
{eq: 8 * time.Second, gte: 0, lte: 0},
{eq: 8 * time.Second, gte: 0, lte: 0},
{eq: 8 * time.Second, gte: 0, lte: 0},
},
seeds: 0,
},
{
backoff: New(
Expand All @@ -113,19 +114,20 @@ func TestLogBackoff(t *testing.T) {
WithSeed(0),
),
exp: []exp{
{eq: time.Second},
{eq: 2 * time.Second},
{eq: 4 * time.Second},
{eq: 8 * time.Second},
{eq: 16 * time.Second},
{eq: 32 * time.Second},
{eq: 64 * time.Second},
{eq: 64 * time.Second},
{eq: 64 * time.Second},
{eq: 64 * time.Second},
{eq: 64 * time.Second},
{eq: 64 * time.Second},
{eq: time.Second, gte: 0, lte: 0},
{eq: 2 * time.Second, gte: 0, lte: 0},
{eq: 4 * time.Second, gte: 0, lte: 0},
{eq: 8 * time.Second, gte: 0, lte: 0},
{eq: 16 * time.Second, gte: 0, lte: 0},
{eq: 32 * time.Second, gte: 0, lte: 0},
{eq: 64 * time.Second, gte: 0, lte: 0},
{eq: 64 * time.Second, gte: 0, lte: 0},
{eq: 64 * time.Second, gte: 0, lte: 0},
{eq: 64 * time.Second, gte: 0, lte: 0},
{eq: 64 * time.Second, gte: 0, lte: 0},
{eq: 64 * time.Second, gte: 0, lte: 0},
},
seeds: 0,
},
} {
t.Run("", func(t *testing.T) {
Expand Down

0 comments on commit aca0292

Please sign in to comment.