2016-07-08 22:36:53 +08:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-01-09 19:58:23 +08:00
|
|
|
"github.com/anacrolix/missinggo/v2/resource"
|
2016-07-08 22:36:53 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2019-08-21 18:58:40 +08:00
|
|
|
|
|
|
|
"github.com/anacrolix/torrent/metainfo"
|
2016-07-08 22:36:53 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Two different torrents opened from the same storage. Closing one should not
|
|
|
|
// break the piece completion on the other.
|
2016-09-02 13:10:57 +08:00
|
|
|
func testIssue95(t *testing.T, c ClientImpl) {
|
2016-08-26 18:29:05 +08:00
|
|
|
i1 := &metainfo.Info{
|
|
|
|
Files: []metainfo.FileInfo{{Path: []string{"a"}}},
|
|
|
|
Pieces: make([]byte, 20),
|
2016-07-08 22:36:53 +08:00
|
|
|
}
|
2016-08-26 18:29:05 +08:00
|
|
|
t1, err := c.OpenTorrent(i1, metainfo.HashBytes([]byte("a")))
|
2016-07-08 22:36:53 +08:00
|
|
|
require.NoError(t, err)
|
2016-08-26 18:29:05 +08:00
|
|
|
i2 := &metainfo.Info{
|
|
|
|
Files: []metainfo.FileInfo{{Path: []string{"a"}}},
|
|
|
|
Pieces: make([]byte, 20),
|
2016-07-08 22:36:53 +08:00
|
|
|
}
|
2016-08-26 18:29:05 +08:00
|
|
|
t2, err := c.OpenTorrent(i2, metainfo.HashBytes([]byte("b")))
|
2016-07-08 22:36:53 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
t2p := t2.Piece(i2.Piece(0))
|
|
|
|
assert.NoError(t, t1.Close())
|
2017-10-12 13:09:32 +08:00
|
|
|
assert.NotPanics(t, func() { t2p.Completion() })
|
2016-07-08 22:36:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestIssue95File(t *testing.T) {
|
2022-02-02 15:26:46 +08:00
|
|
|
td := t.TempDir()
|
2016-07-08 22:36:53 +08:00
|
|
|
testIssue95(t, NewFile(td))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIssue95MMap(t *testing.T) {
|
2022-02-02 15:26:46 +08:00
|
|
|
td := t.TempDir()
|
2016-07-08 22:36:53 +08:00
|
|
|
testIssue95(t, NewMMap(td))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIssue95ResourcePieces(t *testing.T) {
|
|
|
|
testIssue95(t, NewResourcePieces(resource.OSFileProvider{}))
|
|
|
|
}
|