FedP2P/issue211_test.go

43 lines
943 B
Go
Raw Permalink Normal View History

2021-06-23 15:24:50 +08:00
//go:build !wasm
// +build !wasm
2021-06-23 15:24:50 +08:00
2017-12-01 15:11:20 +08:00
package torrent
import (
"io"
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/time/rate"
2019-08-21 18:58:40 +08:00
"github.com/anacrolix/torrent/internal/testutil"
"github.com/anacrolix/torrent/storage"
2017-12-01 15:11:20 +08:00
)
2017-12-01 15:13:21 +08:00
func TestDropTorrentWithMmapStorageWhileHashing(t *testing.T) {
cfg := TestingConfig(t)
2017-12-01 15:11:20 +08:00
// Ensure the data is present when the torrent is added, and not obtained
// over the network as the test runs.
cfg.DownloadRateLimiter = rate.NewLimiter(0, 0)
cl, err := NewClient(cfg)
require.NoError(t, err)
defer cl.Close()
td, mi := testutil.GreetingTestTorrent()
2021-12-16 08:41:31 +08:00
mms := storage.NewMMap(td)
defer mms.Close()
2017-12-01 15:11:20 +08:00
tt, new, err := cl.AddTorrentSpec(&TorrentSpec{
2021-12-16 08:41:31 +08:00
Storage: mms,
2017-12-01 15:11:20 +08:00
InfoHash: mi.HashInfoBytes(),
InfoBytes: mi.InfoBytes,
})
require.NoError(t, err)
assert.True(t, new)
r := tt.NewReader()
go tt.Drop()
io.Copy(ioutil.Discard, r)
}