]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Add test that dirty chunks are cleared on piece hash failure
authorMatt Joiner <anacrolix@gmail.com>
Tue, 6 Dec 2016 04:41:08 +0000 (15:41 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 6 Dec 2016 04:41:08 +0000 (15:41 +1100)
torrent_test.go

index a0d0857c69ce972abd490202bdafa01accb59197..9fe3e96374ff5c3cbe25277b1567d5e92c73587b 100644 (file)
@@ -11,6 +11,7 @@ import (
        "github.com/stretchr/testify/require"
 
        "github.com/anacrolix/torrent/bencode"
+       "github.com/anacrolix/torrent/internal/testutil"
        "github.com/anacrolix/torrent/metainfo"
        "github.com/anacrolix/torrent/peer_protocol"
        "github.com/anacrolix/torrent/storage"
@@ -131,3 +132,19 @@ func TestEmptyFilesAndZeroPieceLengthWithFileStorage(t *testing.T) {
 func TestEmptyFilesAndZeroPieceLengthWithMMapStorage(t *testing.T) {
        testEmptyFilesAndZeroPieceLength(t, storage.NewMMap(TestingConfig.DataDir))
 }
+
+func TestPieceHashFailed(t *testing.T) {
+       mi := testutil.GreetingMetaInfo()
+       tt := Torrent{
+               cl:            new(Client),
+               infoHash:      mi.HashInfoBytes(),
+               storageOpener: storage.NewClient(badStorage{}),
+               chunkSize:     2,
+       }
+       require.NoError(t, tt.setInfoBytes(mi.InfoBytes))
+       tt.pieces[1].DirtyChunks.AddRange(0, 3)
+       require.True(t, tt.pieceAllDirty(1))
+       tt.pieceHashed(1, false)
+       // Dirty chunks should be cleared so we can try again.
+       require.False(t, tt.pieceAllDirty(1))
+}