2016-07-12 06:42:54 +00:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"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)
|
2016-09-02 05:10:57 +00:00
|
|
|
cs := storage.NewClient(storage.NewFile(td))
|
2016-07-12 06:42:54 +00:00
|
|
|
tt := &Torrent{}
|
2016-08-26 10:29:05 +00:00
|
|
|
mi := testutil.GreetingMetaInfo()
|
|
|
|
info := mi.UnmarshalInfo()
|
|
|
|
tt.info = &info
|
2016-07-12 06:42:54 +00:00
|
|
|
tt.makePieces()
|
2016-08-26 10:29:05 +00:00
|
|
|
tt.storage, err = cs.OpenTorrent(tt.info, mi.HashInfoBytes())
|
2016-07-12 06:42:54 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, tt.storage.Close())
|
|
|
|
tt.hashPiece(0)
|
|
|
|
}
|