Skip to content

Commit

Permalink
fix: Revert golangci and ratelimiter changes per review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
devin-ai-integration[bot] and trajan0x committed Dec 19, 2024
1 parent 2814e92 commit bcaf693
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 107 deletions.
112 changes: 88 additions & 24 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,115 @@ run:
- otelginmetrics/*
timeout: 15m
skip-files:
- '.*\.abigen\.go$'
- '.*\.metadata\.go$'
- '.*\.pb\.go$'
- '.*\\.abigen\\.go$'
- '.*\\.metadata\\.go$'
- '.*\\.pb\\.go$'
- '.*_gen.go$'

linters-settings:
gofmt:
simplify: true
govet:
# Don't report about shadowed variables
check-shadowing: false
misspell:
locale: US
gocritic:
disabled-checks:
- appendAssign
cyclop:
max-complexity: 15

linters:
disable-all: true
enable:
- gofmt
- govet
- gosimple
- staticcheck
- errcheck
- ineffassign
- unused
- gosec
- cyclop
- revive
- stylecheck
- gocritic
- misspell
enable-all: true
disable:
# Global variables are used in many places throughout the code base.
- gochecknoglobals

# Some lines are over 80 characters on purpose and we don't want to make them
# even longer by marking them as 'nolint'.
- lll

# We don't care (enough) about misaligned structs to lint that.
- maligned

# We have long functions, especially in tests. Moving or renaming those would
# trigger funlen problems that we may not want to solve at that time.
- funlen

# Disable for now as we haven't yet tuned the sensitivity to our codebase
# yet. Enabling by default for example, would also force new contributors to
# potentially extensively refactor code, when they want to smaller change to
# land.
- gocyclo
- dupl
- wrapcheck

# Instances of table driven tests that don't pre-allocate shouldn't trigger
# the linter.
- prealloc

# Init functions are used by loggers throughout the codebase.
- gochecknoinits
# this messes with formatting
- goimports
# TODO implement paralell tests
- paralleltest
# remove
- wsl
# skip for post set
- exhaustruct
- exhaustivestruct
# if short
- ifshort
# we want to use todo
- godox
# skip new line return until autofix works for it
- nlreturn
# go 1.13 error
- goerr113
# disable gci
- gci
# disable gofumpt
- gofumpt
# allow magic numbers
- gomnd
# allow println
- forbidigo
# disabled (todo: enable)
- interfacer
# Allow nolint
- nolintlint
# we use external json tags
- tagliatelle
# var name len
- varnamelen
# allow replacements
- gomoddirectives
# no need to disallow returning interfaces
- ireturn
- nonamedreturns
- contextcheck
- nosnakecase
- depguard
# we use core/testsuite.Err() etc that don't get caught by this linter and result in false positives.
- testifylint
# we use metrics.EndSpan and metrics.EndSpanWithErr so this gets triggered falsely
- spancheck
# simply annoying
- perfsprint
# malfunctions on embedded structs
- typecheck
# magic numbers
- mnd
# constants
- goconst
fast: false

issues:
# We use dot imports extensively in tests. Usually for testify assertions
exclude-rules:
- path: _test\.go
linters:
- revive
- stylecheck
- dupl
# wrapping errors when exporting for testing is tedious
- path: export_test\.go
linters:
- wrapcheck
Expand All @@ -76,7 +140,7 @@ issues:
- cyclop
- path: signoz/*
linters:
- mnd
- gomnd
- stylecheck
- path: example/*
linters:
Expand Down
58 changes: 0 additions & 58 deletions tools/.golangci.yml

This file was deleted.

15 changes: 10 additions & 5 deletions tools/abigen/internal/etherscan/ratelimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ import (

// fileRateLimiter implements a file based rate limiter for limiting requests across abi generate commands.
type fileRateLimiter struct {
mux sync.Mutex // Mutex (40-byte alignment)
waitBetweenRequests time.Duration // Duration (8-byte alignment)
flock *flock.Flock // Pointer (8-byte alignment)
lastRequestFile *os.File // Pointer (8-byte alignment)
lockFolderPath string // String (8-byte alignment)
// lockFolderPath is the path to the rate limiter
lockFolderPath string
// flock is the file locker for recording the last request. This is locked per process to prevent two from running at once
flock *flock.Flock
// waitBetweenRequests is how long to wait before requests
waitBetweenRequests time.Duration
// lastRequestFile is the last request file
lastRequestFile *os.File
// mux prevents duplicate locking
mux sync.Mutex
}

// fileRateTimeout is how long to wait for file rate limiting.
Expand Down
35 changes: 15 additions & 20 deletions tools/abigen/internal/etherscan/ratelimiter_test.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
package etherscan_test

import (
"context"
"time"

"github.com/Flaque/filet"
. "github.com/stretchr/testify/assert"
"github.com/synapsecns/sanguine/tools/abigen/internal/etherscan"
"time"
)

// PLACEHOLDER: EtherscanSuite is defined in suite_test.go
var waitTime = time.Second

// PLACEHOLDER: TestEtherscanSuite function implementation
func (s EtherscanSuite) TestRateLimiter() {
lockPath := filet.TmpDir(s.T(), "")

func (s *EtherscanSuite) TestRateLimiter() {
waitTime := time.Second
lockPath := filet.TmpDir(s.TestSuite.T(), "")

rateLimiter, err := etherscan.NewFileRateLimiter(context.Background(), lockPath, waitTime)
s.TestSuite.Require().NoError(err)
rateLimiter, err := etherscan.NewFileRateLimiter(s.GetTestContext(), lockPath, waitTime)
Nil(s.T(), err)

for lockCount := 0; lockCount < 2; lockCount++ {
expectedEndTime := time.Now().Add(waitTime)
// obtain lock obtains the lcok
ok, err := rateLimiter.ObtainLock(s.GetTestContext())
True(s.T(), ok)
Nil(s.T(), err)

// obtain lock obtains the lock
ok, err := rateLimiter.ObtainLock(context.Background())
s.TestSuite.Assert().True(ok)
s.TestSuite.Require().NoError(err)

// release lock releases the lock
// release lock releases the lcok
ok, err = rateLimiter.ReleaseLock()
s.TestSuite.Assert().True(ok)
s.TestSuite.Require().NoError(err)
True(s.T(), ok)
Nil(s.T(), err)

s.TestSuite.Assert().GreaterOrEqual(expectedEndTime.UnixNano(), time.Now().UnixNano())
GreaterOrEqual(s.T(), expectedEndTime.UnixNano(), time.Now().UnixNano())
}
}

0 comments on commit bcaf693

Please sign in to comment.