github.com/anacrolix/torrent@v1.61.0/storage/issue95_test.go (about) 1 package storage 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/anacrolix/missinggo/v2/resource" 8 "github.com/go-quicktest/qt" 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, ci ClientImpl) { 16 info := metainfo.Info{ 17 Files: []metainfo.FileInfo{{Path: []string{"a"}, Length: 1}}, 18 Pieces: make([]byte, 20), 19 PieceLength: 1, 20 } 21 c := NewClient(ci) 22 t1, err := c.OpenTorrent(context.Background(), &info, metainfo.HashBytes([]byte("a"))) 23 qt.Assert(t, qt.IsNil(err)) 24 defer t1.Close() 25 t2, err := c.OpenTorrent(context.Background(), &info, metainfo.HashBytes([]byte("b"))) 26 qt.Assert(t, qt.IsNil(err)) 27 defer t2.Close() 28 t2p := t2.Piece(info.Piece(0)) 29 qt.Check(t, qt.IsNil(t1.Close())) 30 t2p.Completion() 31 } 32 33 func TestIssue95File(t *testing.T) { 34 td := t.TempDir() 35 cs := NewFile(td) 36 defer cs.Close() 37 testIssue95(t, cs) 38 } 39 40 func TestIssue95MMap(t *testing.T) { 41 td := t.TempDir() 42 cs := NewMMap(td) 43 defer cs.Close() 44 testIssue95(t, cs) 45 } 46 47 func TestIssue95ResourcePieces(t *testing.T) { 48 testIssue95(t, NewResourcePieces(resource.OSFileProvider{})) 49 }