From: Matt Joiner Date: Fri, 1 Dec 2017 07:11:20 +0000 (+1100) Subject: Add test for #211 X-Git-Tag: v1.0.0~325 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=10f7a8124a9e89b065ac0237118fe3e68969ae17;p=btrtrc.git Add test for #211 --- diff --git a/issue211_test.go b/issue211_test.go new file mode 100644 index 00000000..8a0d8b3b --- /dev/null +++ b/issue211_test.go @@ -0,0 +1,46 @@ +package torrent + +import ( + "io" + "io/ioutil" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "golang.org/x/time/rate" + + "github.com/anacrolix/torrent/internal/testutil" + "github.com/anacrolix/torrent/storage" +) + +func TestDropTorrentWhileHashing(t *testing.T) { + cfg := TestingConfig() + // 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() + tt, new, err := cl.AddTorrentSpec(&TorrentSpec{ + Storage: storage.NewMMap(td), + InfoHash: mi.HashInfoBytes(), + InfoBytes: mi.InfoBytes, + }) + require.NoError(t, err) + assert.True(t, new) + + // Make sure some of the data is actually there. + sub := tt.SubscribePieceStateChanges() + for range sub.Values { + if tt.BytesCompleted() > 0 { + break + } + } + sub.Close() + + r := tt.NewReader() + go tt.Drop() + io.Copy(ioutil.Discard, r) +}