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