2016-04-30 09:08:29 +08:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
2018-01-31 13:42:26 +08:00
|
|
|
"context"
|
2016-04-30 09:08:29 +08:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2018-11-02 20:12:01 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-08-21 18:58:40 +08:00
|
|
|
|
|
|
|
"github.com/anacrolix/torrent/internal/testutil"
|
2016-04-30 09:08:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestReaderReadContext(t *testing.T) {
|
2017-06-01 20:57:08 +08:00
|
|
|
cl, err := NewClient(TestingConfig())
|
2016-04-30 09:08:29 +08:00
|
|
|
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()
|
2016-04-30 09:08:29 +08:00
|
|
|
defer r.Close()
|
2017-08-27 23:42:02 +08:00
|
|
|
_, err = r.ReadContext(ctx, make([]byte, 1))
|
2016-04-30 09:08:29 +08:00
|
|
|
require.EqualValues(t, context.DeadlineExceeded, err)
|
|
|
|
}
|