]> Sergey Matveev's repositories - btrtrc.git/blobdiff - storage/test/bench-piece-mark-complete.go
Fix UseSources panicking when sqlite storage is closed
[btrtrc.git] / storage / test / bench-piece-mark-complete.go
index 6e04702bc2c448d07b1f8384094b3fb691b513c9..db0049f22674b98ff499bd12745799133d01869a 100644 (file)
@@ -6,10 +6,10 @@ import (
        "sync"
        "testing"
 
+       qt "github.com/frankban/quicktest"
+
        "github.com/anacrolix/torrent/metainfo"
        "github.com/anacrolix/torrent/storage"
-       "github.com/bradfitz/iter"
-       qt "github.com/frankban/quicktest"
 )
 
 const (
@@ -41,7 +41,7 @@ func BenchmarkPieceMarkComplete(
        readData := make([]byte, pieceSize)
        b.SetBytes(int64(numPieces) * pieceSize)
        oneIter := func() {
-               for pieceIndex := range iter.N(numPieces) {
+               for pieceIndex := 0; pieceIndex < numPieces; pieceIndex += 1 {
                        pi := tw.Piece(info.Piece(pieceIndex))
                        rand.Read(data)
                        b.StartTimer()
@@ -66,7 +66,7 @@ func BenchmarkPieceMarkComplete(
                        // This might not apply if users of this benchmark don't cache with the expected capacity.
                        c.Assert(pi.Completion(), qt.Equals, storage.Completion{Complete: false, Ok: true})
                        c.Assert(pi.MarkComplete(), qt.IsNil)
-                       c.Assert(pi.Completion(), qt.Equals, storage.Completion{true, true})
+                       c.Assert(pi.Completion(), qt.Equals, storage.Completion{Complete: true, Ok: true})
                        n, err := pi.WriteTo(bytes.NewBuffer(readData[:0]))
                        b.StopTimer()
                        c.Assert(err, qt.IsNil)
@@ -76,12 +76,13 @@ func BenchmarkPieceMarkComplete(
        }
        // Fill the cache
        if capacity > 0 {
-               for range iter.N(int((capacity + info.TotalLength() - 1) / info.TotalLength())) {
+               iterN := int((capacity + info.TotalLength() - 1) / info.TotalLength())
+               for i := 0; i < iterN; i += 1 {
                        oneIter()
                }
        }
        b.ResetTimer()
-       for range iter.N(b.N) {
+       for i := 0; i < b.N; i += 1 {
                oneIter()
        }
 }