]> Sergey Matveev's repositories - btrtrc.git/blob - storage/issue95_test.go
bda208699fe1df032212a9eb6c29ea8c9be0c229
[btrtrc.git] / storage / issue95_test.go
1 package storage
2
3 import (
4         "testing"
5
6         "github.com/anacrolix/missinggo/v2/resource"
7         "github.com/stretchr/testify/assert"
8         "github.com/stretchr/testify/require"
9
10         "github.com/anacrolix/torrent/metainfo"
11 )
12
13 // Two different torrents opened from the same storage. Closing one should not
14 // break the piece completion on the other.
15 func testIssue95(t *testing.T, c ClientImpl) {
16         i1 := &metainfo.Info{
17                 Files:  []metainfo.FileInfo{{Path: []string{"a"}}},
18                 Pieces: make([]byte, 20),
19         }
20         t1, err := c.OpenTorrent(i1, metainfo.HashBytes([]byte("a")))
21         require.NoError(t, err)
22         i2 := &metainfo.Info{
23                 Files:  []metainfo.FileInfo{{Path: []string{"a"}}},
24                 Pieces: make([]byte, 20),
25         }
26         t2, err := c.OpenTorrent(i2, metainfo.HashBytes([]byte("b")))
27         require.NoError(t, err)
28         t2p := t2.Piece(i2.Piece(0))
29         assert.NoError(t, t1.Close())
30         assert.NotPanics(t, func() { t2p.Completion() })
31 }
32
33 func TestIssue95File(t *testing.T) {
34         td := t.TempDir()
35         testIssue95(t, NewFile(td))
36 }
37
38 func TestIssue95MMap(t *testing.T) {
39         td := t.TempDir()
40         testIssue95(t, NewMMap(td))
41 }
42
43 func TestIssue95ResourcePieces(t *testing.T) {
44         testIssue95(t, NewResourcePieces(resource.OSFileProvider{}))
45 }