FedP2P/reader_test.go

27 lines
634 B
Go
Raw Permalink Normal View History

package torrent
import (
2018-01-31 13:42:26 +08:00
"context"
"testing"
"time"
"github.com/stretchr/testify/require"
2019-08-21 18:58:40 +08:00
"github.com/anacrolix/torrent/internal/testutil"
)
func TestReaderReadContext(t *testing.T) {
cl, err := NewClient(TestingConfig(t))
require.NoError(t, err)
defer cl.Close()
tt, err := cl.AddTorrent(testutil.GreetingMetaInfo())
require.NoError(t, err)
defer tt.Drop()
2018-02-02 16:28:09 +08:00
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Millisecond))
defer cancel()
2018-01-06 13:37:13 +08:00
r := tt.Files()[0].NewReader()
defer r.Close()
_, err = r.ReadContext(ctx, make([]byte, 1))
require.EqualValues(t, context.DeadlineExceeded, err)
}