github.com/anacrolix/torrent@v1.61.0/issue211_test.go (about) 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 cfg.DialForPeerConns = false 24 cfg.AcceptPeerConnections = false 25 cl, err := NewClient(cfg) 26 require.NoError(t, err) 27 defer cl.Close() 28 29 td, mi := testutil.GreetingTestTorrent() 30 mms := storage.NewMMap(td) 31 defer mms.Close() 32 tt, new := cl.AddTorrentOpt(AddTorrentOpts{ 33 Storage: mms, 34 InfoHash: mi.HashInfoBytes(), 35 InfoBytes: mi.InfoBytes, 36 }) 37 assert.True(t, new) 38 39 r := tt.NewReader() 40 go tt.Drop() 41 io.Copy(io.Discard, r) 42 }