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