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