diff --git a/lib/persistentqueue/fastqueue_test.go b/lib/persistentqueue/fastqueue_test.go index 5dbfe3cc35..0faea22d94 100644 --- a/lib/persistentqueue/fastqueue_test.go +++ b/lib/persistentqueue/fastqueue_test.go @@ -12,7 +12,7 @@ import ( func TestFastQueueOpenClose(_ *testing.T) { path := "fast-queue-open-close" fs.MustRemoveDir(path) - for i := 0; i < 10; i++ { + for range 10 { fq := MustOpenFastQueue(path, "foobar", 100, 0, false) fq.MustClose() } @@ -29,7 +29,7 @@ func TestFastQueueWriteReadInmemory(t *testing.T) { t.Fatalf("unexpected non-zero inmemory queue size: %d", n) } var blocks []string - for i := 0; i < capacity; i++ { + for i := range capacity { block := fmt.Sprintf("block %d", i) if !fq.TryWriteBlock([]byte(block)) { t.Fatalf("TryWriteBlock must return true in this context") @@ -62,7 +62,7 @@ func TestFastQueueWriteReadMixed(t *testing.T) { t.Fatalf("the number of pending bytes must be 0; got %d", n) } var blocks []string - for i := 0; i < 2*capacity; i++ { + for i := range 2 * capacity { block := fmt.Sprintf("block %d", i) if !fq.TryWriteBlock([]byte(block)) { t.Fatalf("TryWriteBlock must return true in this context") @@ -98,7 +98,7 @@ func TestFastQueueWriteReadWithCloses(t *testing.T) { t.Fatalf("the number of pending bytes must be 0; got %d", n) } var blocks []string - for i := 0; i < 2*capacity; i++ { + for i := range 2 * capacity { block := fmt.Sprintf("block %d", i) if !fq.TryWriteBlock([]byte(block)) { t.Fatalf("TryWriteBlock must return true in this context") @@ -202,7 +202,7 @@ func TestFastQueueReadWriteConcurrent(t *testing.T) { var blocks []string blocksMap := make(map[string]bool) var blocksMapLock sync.Mutex - for i := 0; i < 1000; i++ { + for i := range 1000 { block := fmt.Sprintf("block %d", i) blocks = append(blocks, block) blocksMap[block] = true @@ -298,7 +298,7 @@ func TestFastQueueWriteReadWithDisabledPQ(t *testing.T) { t.Fatalf("unexpected non-zero inmemory queue size: %d", n) } var blocks []string - for i := 0; i < capacity; i++ { + for i := range capacity { block := fmt.Sprintf("block %d", i) if !fq.TryWriteBlock([]byte(block)) { t.Fatalf("TryWriteBlock must return true in this context") @@ -334,7 +334,7 @@ func TestFastQueueWriteReadWithIgnoreDisabledPQ(t *testing.T) { t.Fatalf("unexpected non-zero inmemory queue size: %d", n) } var blocks []string - for i := 0; i < capacity; i++ { + for i := range capacity { block := fmt.Sprintf("block %d", i) if !fq.TryWriteBlock([]byte(block)) { t.Fatalf("TryWriteBlock must return true in this context") @@ -344,7 +344,7 @@ func TestFastQueueWriteReadWithIgnoreDisabledPQ(t *testing.T) { if fq.TryWriteBlock([]byte("error-block")) { t.Fatalf("expect false due to full queue") } - for i := 0; i < capacity; i++ { + for i := range capacity { block := fmt.Sprintf("block %d-%d", i, i) fq.MustWriteBlockIgnoreDisabledPQ([]byte(block)) blocks = append(blocks, block) diff --git a/lib/persistentqueue/fastqueue_timing_test.go b/lib/persistentqueue/fastqueue_timing_test.go index 81b4a696ab..63288856a1 100644 --- a/lib/persistentqueue/fastqueue_timing_test.go +++ b/lib/persistentqueue/fastqueue_timing_test.go @@ -22,7 +22,7 @@ func BenchmarkFastQueueThroughputSerial(b *testing.B) { fq.MustClose() fs.MustRemoveDir(path) }() - for i := 0; i < b.N; i++ { + for range b.N { writeReadIterationFastQueue(fq, block, iterationsCount) } }) @@ -53,14 +53,14 @@ func BenchmarkFastQueueThroughputConcurrent(b *testing.B) { } func writeReadIterationFastQueue(fq *FastQueue, block []byte, iterationsCount int) { - for i := 0; i < iterationsCount; i++ { + for range iterationsCount { if !fq.TryWriteBlock(block) { panic(fmt.Errorf("TryWriteBlock must return true")) } } var ok bool bb := bbPool.Get() - for i := 0; i < iterationsCount; i++ { + for range iterationsCount { bb.B, ok = fq.MustReadBlock(bb.B[:0]) if !ok { panic(fmt.Errorf("unexpected ok=false")) diff --git a/lib/persistentqueue/persistentqueue_test.go b/lib/persistentqueue/persistentqueue_test.go index 411be90409..b5456b5471 100644 --- a/lib/persistentqueue/persistentqueue_test.go +++ b/lib/persistentqueue/persistentqueue_test.go @@ -13,7 +13,7 @@ import ( func TestQueueOpenClose(t *testing.T) { path := "queue-open-close" fs.MustRemoveDir(path) - for i := 0; i < 3; i++ { + for range 3 { q := mustOpen(path, "foobar", 0) if n := q.GetPendingBytes(); n > 0 { t.Fatalf("pending bytes must be 0; got %d", n) @@ -150,8 +150,8 @@ func TestQueueResetIfEmpty(t *testing.T) { block := make([]byte, 1024*1024) var buf []byte - for j := 0; j < 10; j++ { - for i := 0; i < 10; i++ { + for range 10 { + for range 10 { q.MustWriteBlock(block) var ok bool buf, ok = q.MustReadBlockNonblocking(buf[:0]) @@ -179,9 +179,9 @@ func TestQueueWriteRead(t *testing.T) { fs.MustRemoveDir(path) }() - for j := 0; j < 5; j++ { + for j := range 5 { var blocks [][]byte - for i := 0; i < 10; i++ { + for i := range 10 { block := []byte(fmt.Sprintf("block %d+%d", j, i)) q.MustWriteBlock(block) blocks = append(blocks, block) @@ -215,9 +215,9 @@ func TestQueueWriteCloseRead(t *testing.T) { fs.MustRemoveDir(path) }() - for j := 0; j < 5; j++ { + for j := range 5 { var blocks [][]byte - for i := 0; i < 10; i++ { + for i := range 10 { block := []byte(fmt.Sprintf("block %d+%d", j, i)) q.MustWriteBlock(block) blocks = append(blocks, block) @@ -256,7 +256,7 @@ func TestQueueChunkManagementSimple(t *testing.T) { defer fs.MustRemoveDir(path) defer q.MustClose() var blocks []string - for i := 0; i < 100; i++ { + for i := range 100 { block := fmt.Sprintf("block %d", i) q.MustWriteBlock([]byte(block)) blocks = append(blocks, block) @@ -289,7 +289,7 @@ func TestQueueChunkManagementPeriodicClose(t *testing.T) { fs.MustRemoveDir(path) }() var blocks []string - for i := 0; i < 100; i++ { + for i := range 100 { block := fmt.Sprintf("block %d", i) q.MustWriteBlock([]byte(block)) blocks = append(blocks, block) @@ -327,7 +327,7 @@ func TestQueueLimitedSize(t *testing.T) { // Check that small blocks are successfully buffered and read var blocks []string - for i := 0; i < 10; i++ { + for i := range 10 { block := fmt.Sprintf("block_%d", i) q.MustWriteBlock([]byte(block)) blocks = append(blocks, block) @@ -345,7 +345,7 @@ func TestQueueLimitedSize(t *testing.T) { } // Make sure that old blocks are dropped on queue size overflow - for i := 0; i < maxPendingBytes; i++ { + for i := range maxPendingBytes { block := fmt.Sprintf("%d", i) q.MustWriteBlock([]byte(block)) } diff --git a/lib/persistentqueue/persistentqueue_timing_test.go b/lib/persistentqueue/persistentqueue_timing_test.go index 370d66ae77..b0657c0800 100644 --- a/lib/persistentqueue/persistentqueue_timing_test.go +++ b/lib/persistentqueue/persistentqueue_timing_test.go @@ -23,7 +23,7 @@ func BenchmarkQueueThroughputSerial(b *testing.B) { q.MustClose() fs.MustRemoveDir(path) }() - for i := 0; i < b.N; i++ { + for range b.N { writeReadIteration(q, block, iterationsCount) } }) @@ -57,12 +57,12 @@ func BenchmarkQueueThroughputConcurrent(b *testing.B) { } func writeReadIteration(q *queue, block []byte, iterationsCount int) { - for i := 0; i < iterationsCount; i++ { + for range iterationsCount { q.MustWriteBlock(block) } var ok bool bb := bbPool.Get() - for i := 0; i < iterationsCount; i++ { + for range iterationsCount { bb.B, ok = q.MustReadBlockNonblocking(bb.B[:0]) if !ok { panic(fmt.Errorf("unexpected ok=false"))