Skip to content

Commit

Permalink
stricter golangci-lint config, bump go modules
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal authored and umputun committed Apr 26, 2020
1 parent fc4313b commit a9480dd
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
22 changes: 14 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ linters-settings:
- wrapperFunc

linters:
disable-all: true
enable:
- megacheck
- golint
- govet
- unconvert
- megacheck
Expand All @@ -42,19 +42,25 @@ linters:
- typecheck
- ineffassign
- varcheck
- stylecheck
- gochecknoinits
- scopelint
- gocritic
- nakedret
- gosimple
- prealloc
fast: false

disable-all: true

run:
# modules-download-mode: vendor
output:
format: tab
skip-dirs:
- vendor

issues:
exclude-rules:
- text: "weak cryptographic primitive"
- text: "should have a package comment, unless it's in another file for this package"
linters:
- gosec

service:
golangci-lint-version: 1.24.x
- golint
exclude-use-default: false
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ type Interface interface {

Returned channels used as "ticks," i.e., for each repeat or initial operation one read from this channel needed. Closing the channel indicates "done with retries." It is pretty much the same idea as `time.Timer` or `time.Tick` implements. Note - the first (technically not-repeated-yet) call won't happen **until something sent to the channel**. For this reason, the typical strategy sends the first "tick" before the first wait/sleep.

Three strategies provided byt the pacakage:
Three strategies provided byt the package:

1. **Fixed delay**, up to max number of attempts. It is the default strategy used by `repeater.NewDefault` constructor
2. **BackOff** with jitter provides exponential backoff. It starts from `Duration` interval and goes in steps with `last * math.Pow(factor, attempt)`. Optional jitter randomizes intervals a little bit. _Factor = 1 effectively makes this strategy fixed with `Duration` delay._
3. **Once** strategy does not do any repeats and mainly used for tests/mocks`
1. **Fixed delay**, up to max number of attempts. It is the default strategy used by `repeater.NewDefault` constructor.
2. **BackOff** with jitter provides an exponential backoff. It starts from `Duration` interval and goes in steps with `last * math.Pow(factor, attempt)`. Optional jitter randomizes intervals a little. _Factor = 1 effectively makes this strategy fixed with `Duration` delay._
3. **Once** strategy does not do any repeats and mainly used for tests/mocks`.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/go-pkgz/repeater

go 1.14

require github.com/stretchr/testify v1.3.0
require github.com/stretchr/testify v1.5.1
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
5 changes: 3 additions & 2 deletions repeater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func TestRepeaterBackoff(t *testing.T) {
assert.Nil(t, err, "should be ok")
assert.Equal(t, 6, called, "called 6 times")

//nolint:gocritic
t.Log(time.Since(st)) // 100 + 100 * 2^1 + 100 * 2^2 + 100 * 2^3 + 100 * 2^4 = 3100
assert.True(t, time.Since(st) >= 3100*time.Millisecond && time.Since(st) < 4100*time.Millisecond,
fmt.Sprintf("took %s", time.Since(st)))
Expand Down Expand Up @@ -242,7 +243,7 @@ func TestRepeaterMemoryLeakFixed(t *testing.T) {
}

before := runtime.NumGoroutine()
num := []int{}
var num []int
for i := 0; i < 25; i++ {
rep()
num = append(num, runtime.NumGoroutine())
Expand Down Expand Up @@ -271,7 +272,7 @@ func TestRepeaterMemoryLeakBackOff(t *testing.T) {
}

before := runtime.NumGoroutine()
num := []int{}
var num []int
for i := 0; i < 25; i++ {
rep()
num = append(num, runtime.NumGoroutine())
Expand Down
2 changes: 1 addition & 1 deletion strategy/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Interface interface {
type Once struct{}

// Start returns closed channel with a single element to prevent any repeats
func (s *Once) Start(ctx context.Context) <-chan struct{} {
func (s *Once) Start(_ context.Context) <-chan struct{} {
ch := make(chan struct{})
go func() {
ch <- struct{}{}
Expand Down

0 comments on commit a9480dd

Please sign in to comment.