2
0
mirror of synced 2025-02-23 14:18:13 +00:00
torrent/reader_test.go
Matt Joiner f62ff2f540 Add Reader.ReadContext
Allows cancelling reads etc. Torrents that get stuck can result in Reads that won't return until the torrent is dropped.
2016-04-30 11:08:29 +10:00

26 lines
600 B
Go

package torrent
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/anacrolix/torrent/internal/testutil"
)
func TestReaderReadContext(t *testing.T) {
cl, err := NewClient(&TestingConfig)
require.NoError(t, err)
defer cl.Close()
tt, err := cl.AddTorrent(testutil.GreetingMetaInfo())
require.NoError(t, err)
defer tt.Drop()
ctx, _ := context.WithDeadline(context.Background(), time.Now().Add(time.Millisecond))
r := tt.NewReader()
defer r.Close()
_, err = r.ReadContext(make([]byte, 1), ctx)
require.EqualValues(t, context.DeadlineExceeded, err)
}