Skip to content

Commit 95d73ef

Browse files
committed
all: Run modernize -fix ./...
1 parent 743be9d commit 95d73ef

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

‎lazycache_test.go‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestCache(t *testing.T) {
3333
cache.Set(123456, 32)
3434
c.Assert(get(123456), qt.Equals, 32)
3535

36-
for i := 0; i < 20; i++ {
36+
for i := range 20 {
3737
cache.Set(i, i)
3838
}
3939
c.Assert(get(123456), qt.IsNil)
@@ -75,13 +75,13 @@ func TestPanic(t *testing.T) {
7575
}
7676
}
7777

78-
for i := 0; i < 2; i++ {
79-
for j := 0; j < 2; j++ {
78+
for i := range 2 {
79+
for range 2 {
8080
c.Assert(willPanic(i), qt.PanicMatches, fmt.Sprintf("failed-%d", i))
8181
}
8282
}
8383

84-
for i := 0; i < 2; i++ {
84+
for i := range 2 {
8585
v, _, err := cache.GetOrCreate(i, func(key int) (any, error) {
8686
return key + 2, nil
8787
})
@@ -95,7 +95,7 @@ func TestDeleteFunc(t *testing.T) {
9595

9696
c.Run("Basic", func(c *qt.C) {
9797
cache := New(Options[int, any]{MaxEntries: 1000})
98-
for i := 0; i < 10; i++ {
98+
for i := range 10 {
9999
cache.Set(i, i)
100100
}
101101
c.Assert(cache.DeleteFunc(func(key int, value any) bool {
@@ -109,9 +109,9 @@ func TestDeleteFunc(t *testing.T) {
109109

110110
// There's some timing involved in this test, so we'll need
111111
// to retry a few times to cover all the cases.
112-
for i := 0; i < 100; i++ {
112+
for range 100 {
113113
cache := New(Options[int, any]{MaxEntries: 1000})
114-
for i := 0; i < 10; i++ {
114+
for i := range 10 {
115115
cache.Set(i, i)
116116
}
117117
wg.Add(1)
@@ -153,7 +153,7 @@ func TestGetOrCreate(t *testing.T) {
153153
counter++
154154
return fmt.Sprintf("value-%d-%d", key, counter), nil
155155
}
156-
for i := 0; i < 3; i++ {
156+
for i := range 3 {
157157
res, found, err := cache.GetOrCreate(123456, create)
158158
c.Assert(err, qt.IsNil)
159159
c.Assert(res, qt.Equals, "value-123456-1")
@@ -187,7 +187,7 @@ func TestOnEvict(t *testing.T) {
187187
return key, nil
188188
}
189189

190-
for i := 0; i < 25; i++ {
190+
for i := range 25 {
191191
cache.GetOrCreate(i, create)
192192
}
193193

@@ -212,27 +212,27 @@ func TestGetOrCreateConcurrent(t *testing.T) {
212212

213213
var wg sync.WaitGroup
214214

215-
for i := 0; i < 20; i++ {
215+
for i := range 20 {
216216
i := i
217217
expect := fmt.Sprintf("%d-0", i)
218218
wg.Add(1)
219219
go func() {
220220
defer wg.Done()
221-
for j := 0; j < 12; j++ {
221+
for range 12 {
222222
res, _, err := cache.GetOrCreate(i, create)
223223
c.Assert(err, qt.IsNil)
224224
c.Assert(res, qt.Equals, expect)
225225
}
226226
}()
227227
}
228228

229-
for i := 0; i < 20; i++ {
229+
for i := range 20 {
230230
i := i
231231
expect := fmt.Sprintf("%d-0", i)
232232
wg.Add(1)
233233
go func() {
234234
defer wg.Done()
235-
for j := 0; j < 12; j++ {
235+
for range 12 {
236236
countersmu.Lock()
237237
_, created := counters[i]
238238
countersmu.Unlock()
@@ -263,12 +263,12 @@ func TestGetOrCreateAndResizeConcurrent(t *testing.T) {
263263

264264
var wg sync.WaitGroup
265265

266-
for i := 0; i < 100; i++ {
266+
for i := range 100 {
267267
i := i
268268
wg.Add(1)
269269
go func() {
270270
defer wg.Done()
271-
for j := 0; j < 12; j++ {
271+
for range 12 {
272272
v, _, err := cache.GetOrCreate(i, create)
273273
c.Assert(err, qt.IsNil)
274274
c.Assert(v, qt.Not(qt.Equals), 0)
@@ -295,14 +295,14 @@ func TestGetOrCreateRecursive(t *testing.T) {
295295

296296
n := 200
297297

298-
for i := 0; i < 30; i++ {
298+
for range 30 {
299299
cache := New(Options[int, any]{MaxEntries: 1000})
300300

301-
for j := 0; j < 10; j++ {
301+
for range 10 {
302302
wg.Add(1)
303303
go func() {
304304
defer wg.Done()
305-
for k := 0; k < 10; k++ {
305+
for range 10 {
306306
// This test was added to test a deadlock situation with nested GetOrCreate calls on the same cache.
307307
// Note that the keys below are carefully selected to not overlap, as this case may still deadlock:
308308
// goroutine 1: GetOrCreate(1) => GetOrCreate(2)
@@ -345,7 +345,7 @@ func BenchmarkGetOrCreateAndGet(b *testing.B) {
345345
r := rand.New(rand.NewSource(99))
346346
var mu sync.Mutex
347347
// Partially fill the cache.
348-
for i := 0; i < maxSize/2; i++ {
348+
for i := range maxSize / 2 {
349349
cache.Set(i, i)
350350
}
351351
b.ResetTimer()
@@ -389,7 +389,7 @@ func BenchmarkGetOrCreate(b *testing.B) {
389389
cache := New(Options[int, any]{MaxEntries: maxSize})
390390

391391
// Partially fill the cache.
392-
for i := 0; i < maxSize/3; i++ {
392+
for i := range maxSize / 3 {
393393
cache.Set(i, i)
394394
}
395395
b.ResetTimer()
@@ -431,7 +431,7 @@ func BenchmarkCacheSerial(b *testing.B) {
431431
b.Run("Get", func(b *testing.B) {
432432
cache := New(Options[int, any]{MaxEntries: maxSize})
433433
numItems := maxSize - 200
434-
for i := 0; i < numItems; i++ {
434+
for i := range numItems {
435435
cache.Set(i, i)
436436
}
437437
b.ResetTimer()
@@ -464,7 +464,7 @@ func BenchmarkCacheParallel(b *testing.B) {
464464
r := rand.New(rand.NewSource(99))
465465
var mu sync.Mutex
466466
numItems := maxSize - 200
467-
for i := 0; i < numItems; i++ {
467+
for i := range numItems {
468468
cache.Set(i, i)
469469
}
470470
b.RunParallel(func(pb *testing.PB) {

0 commit comments

Comments
 (0)