]> Sergey Matveev's repositories - btrtrc.git/blob - issue211_test.go
Add test for #211
[btrtrc.git] / issue211_test.go
1 package torrent
2
3 import (
4         "io"
5         "io/ioutil"
6         "testing"
7
8         "github.com/stretchr/testify/assert"
9         "github.com/stretchr/testify/require"
10         "golang.org/x/time/rate"
11
12         "github.com/anacrolix/torrent/internal/testutil"
13         "github.com/anacrolix/torrent/storage"
14 )
15
16 func TestDropTorrentWhileHashing(t *testing.T) {
17         cfg := TestingConfig()
18         // Ensure the data is present when the torrent is added, and not obtained
19         // over the network as the test runs.
20         cfg.DownloadRateLimiter = rate.NewLimiter(0, 0)
21         cl, err := NewClient(cfg)
22         require.NoError(t, err)
23         defer cl.Close()
24
25         td, mi := testutil.GreetingTestTorrent()
26         tt, new, err := cl.AddTorrentSpec(&TorrentSpec{
27                 Storage:   storage.NewMMap(td),
28                 InfoHash:  mi.HashInfoBytes(),
29                 InfoBytes: mi.InfoBytes,
30         })
31         require.NoError(t, err)
32         assert.True(t, new)
33
34         // Make sure some of the data is actually there.
35         sub := tt.SubscribePieceStateChanges()
36         for range sub.Values {
37                 if tt.BytesCompleted() > 0 {
38                         break
39                 }
40         }
41         sub.Close()
42
43         r := tt.NewReader()
44         go tt.Drop()
45         io.Copy(ioutil.Discard, r)
46 }