2016-07-12 14:42:54 +08:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2020-01-07 16:18:07 +08:00
|
|
|
"github.com/anacrolix/log"
|
2019-08-21 18:58:40 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2016-07-12 14:42:54 +08:00
|
|
|
"github.com/anacrolix/torrent/internal/testutil"
|
|
|
|
"github.com/anacrolix/torrent/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHashPieceAfterStorageClosed(t *testing.T) {
|
|
|
|
td, err := ioutil.TempDir("", "")
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer os.RemoveAll(td)
|
2018-01-25 14:10:37 +08:00
|
|
|
tt := &Torrent{
|
|
|
|
storageOpener: storage.NewClient(storage.NewFile(td)),
|
2020-01-07 16:18:07 +08:00
|
|
|
logger: log.Default,
|
2021-10-13 12:17:48 +08:00
|
|
|
chunkSize: defaultChunkSize,
|
2018-01-25 14:10:37 +08:00
|
|
|
}
|
2016-08-26 18:29:05 +08:00
|
|
|
mi := testutil.GreetingMetaInfo()
|
2016-09-20 16:39:07 +08:00
|
|
|
info, err := mi.UnmarshalInfo()
|
|
|
|
require.NoError(t, err)
|
2018-01-25 14:10:37 +08:00
|
|
|
require.NoError(t, tt.setInfo(&info))
|
2016-07-12 14:42:54 +08:00
|
|
|
require.NoError(t, tt.storage.Close())
|
|
|
|
tt.hashPiece(0)
|
|
|
|
}
|