From 4581e513b6aa89583986e33e24e0459bd6565ba8 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Sat, 10 Feb 2024 22:25:22 +0500 Subject: [PATCH] refactor initialization of structures in internal/backoff --- CHANGELOG.md | 1 + internal/backoff/backoff.go | 5 ++- internal/backoff/backoff_test.go | 68 ++++++++++++++++---------------- 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a37e8efb5..f8e704e91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/internal/backoff/backoff.go b/internal/backoff/backoff.go index 97beef0d9..2c65a8d82 100644 --- a/internal/backoff/backoff.go +++ b/internal/backoff/backoff.go @@ -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 { diff --git a/internal/backoff/backoff_test.go b/internal/backoff/backoff_test.go index 45cd7fd1e..85af1a0a9 100644 --- a/internal/backoff/backoff_test.go +++ b/internal/backoff/backoff_test.go @@ -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, }, @@ -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, }, @@ -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( @@ -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) {