Skip to content

Commit

Permalink
lint-fix
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Parraga <sovietaced@gmail.com>
  • Loading branch information
Sovietaced committed Jan 15, 2025
1 parent 9a40f0a commit 857af1b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions flytestdlib/cache/in_memory_auto_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type InMemoryAutoRefresh struct {
toDelete *syncSet
syncPeriod time.Duration
workqueue workqueue.RateLimitingInterface
parallelizm int
parallelizm uint
lock sync.RWMutex
clock clock.Clock // pluggable clock for unit testing
syncCount atomic.Int32 // internal sync counter for unit testing
Expand All @@ -110,8 +110,8 @@ func NewInMemoryAutoRefresh(
syncCb SyncFunc,
syncRateLimiter workqueue.RateLimiter,
resyncPeriod time.Duration,
parallelizm int,
size int,
parallelizm uint,
size uint,
scope promutils.Scope,
options ...Option,
) (*InMemoryAutoRefresh, error) {
Expand All @@ -121,7 +121,8 @@ func NewInMemoryAutoRefresh(
}

metrics := newMetrics(scope)
lruCache, err := lru.NewWithEvict(size, getEvictionFunction(metrics.Evictions))
// #nosec G115
lruCache, err := lru.NewWithEvict(int(size), getEvictionFunction(metrics.Evictions))
if err != nil {
return nil, fmt.Errorf("creating LRU cache: %w", err)
}

Check warning on line 128 in flytestdlib/cache/in_memory_auto_refresh.go

View check run for this annotation

Codecov / codecov/patch

flytestdlib/cache/in_memory_auto_refresh.go#L127-L128

Added lines #L127 - L128 were not covered by tests
Expand Down Expand Up @@ -150,7 +151,7 @@ func NewInMemoryAutoRefresh(
}

func (w *InMemoryAutoRefresh) Start(ctx context.Context) error {
for i := 0; i < w.parallelizm; i++ {
for i := uint(0); i < w.parallelizm; i++ {
go func(ctx context.Context) {
err := w.sync(ctx)
if err != nil {
Expand Down Expand Up @@ -389,13 +390,13 @@ func (w *InMemoryAutoRefresh) inProcessing(key interface{}) bool {

// Instantiates a new AutoRefresh Cache that syncs items in batches.
func NewAutoRefreshBatchedCache(name string, createBatches CreateBatchesFunc, syncCb SyncFunc, syncRateLimiter workqueue.RateLimiter,
resyncPeriod time.Duration, parallelizm, size int, scope promutils.Scope) (AutoRefresh, error) {
resyncPeriod time.Duration, parallelizm, size uint, scope promutils.Scope) (AutoRefresh, error) {
return NewInMemoryAutoRefresh(name, syncCb, syncRateLimiter, resyncPeriod, parallelizm, size, scope, WithCreateBatchesFunc(createBatches))
}

// Instantiates a new AutoRefresh Cache that syncs items periodically.
func NewAutoRefreshCache(name string, syncCb SyncFunc, syncRateLimiter workqueue.RateLimiter, resyncPeriod time.Duration,
parallelizm, size int, scope promutils.Scope) (AutoRefresh, error) {
parallelizm, size uint, scope promutils.Scope) (AutoRefresh, error) {
return NewAutoRefreshBatchedCache(name, SingleItemBatches, syncCb, syncRateLimiter, resyncPeriod, parallelizm, size, scope)
}

Expand Down
6 changes: 3 additions & 3 deletions flytestdlib/cache/in_memory_auto_refresh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,17 @@ func TestQueueBuildUp(t *testing.T) {
return nil, fmt.Errorf("expected error")
}

size := 100
size := uint(100)
cache, err := NewInMemoryAutoRefresh("fake2", alwaysFailing, rateLimiter, testResyncPeriod, 10, size, promutils.NewTestScope(), WithClock(fakeClock))
assert.NoError(t, err)

ctx, cancel := context.WithCancel(context.Background())
assert.NoError(t, cache.Start(ctx))
defer cancel()

for i := 0; i < size; i++ {
for i := uint(0); i < size; i++ {
// #nosec G115
_, err := cache.GetOrCreate(strconv.Itoa(i), fakeCacheItem{val: 3})
_, err := cache.GetOrCreate(strconv.Itoa(int(i)), fakeCacheItem{val: 3})
assert.NoError(t, err)
}

Expand Down

0 comments on commit 857af1b

Please sign in to comment.