From: Matt Joiner Date: Tue, 6 Dec 2016 04:41:08 +0000 (+1100) Subject: Add test that dirty chunks are cleared on piece hash failure X-Git-Tag: v1.0.0~514^2 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=c8dffdb;p=btrtrc.git Add test that dirty chunks are cleared on piece hash failure --- diff --git a/torrent_test.go b/torrent_test.go index a0d0857c..9fe3e963 100644 --- a/torrent_test.go +++ b/torrent_test.go @@ -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)) +}