2016-07-12 13:27:12 +02:00
|
|
|
package kcp_test
|
|
|
|
|
|
|
|
import (
|
2017-12-03 21:29:27 +01:00
|
|
|
"io"
|
2016-07-12 13:27:12 +02:00
|
|
|
"testing"
|
|
|
|
"time"
|
2016-12-08 16:27:41 +01:00
|
|
|
|
2017-12-03 21:29:27 +01:00
|
|
|
"v2ray.com/core/common/buf"
|
2016-08-20 20:55:45 +02:00
|
|
|
. "v2ray.com/core/transport/internet/kcp"
|
2017-10-26 21:44:22 +02:00
|
|
|
. "v2ray.com/ext/assert"
|
2016-07-12 13:27:12 +02:00
|
|
|
)
|
|
|
|
|
2017-12-03 21:29:27 +01:00
|
|
|
type NoOpCloser int
|
2016-07-12 17:11:36 +02:00
|
|
|
|
2017-12-03 21:29:27 +01:00
|
|
|
func (NoOpCloser) Close() error {
|
2016-07-12 17:11:36 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-07-12 13:27:12 +02:00
|
|
|
func TestConnectionReadTimeout(t *testing.T) {
|
2017-10-24 16:15:35 +02:00
|
|
|
assert := With(t)
|
2016-07-12 13:27:12 +02:00
|
|
|
|
2017-12-03 21:29:27 +01:00
|
|
|
conn := NewConnection(1, &ConnMetadata{}, &KCPPacketWriter{
|
|
|
|
Writer: buf.DiscardBytes,
|
|
|
|
}, NoOpCloser(0), &Config{})
|
2016-07-12 13:27:12 +02:00
|
|
|
conn.SetReadDeadline(time.Now().Add(time.Second))
|
|
|
|
|
|
|
|
b := make([]byte, 1024)
|
|
|
|
nBytes, err := conn.Read(b)
|
2017-10-24 16:15:35 +02:00
|
|
|
assert(nBytes, Equals, 0)
|
|
|
|
assert(err, IsNotNil)
|
2016-10-10 16:50:54 +02:00
|
|
|
|
|
|
|
conn.Terminate()
|
2016-07-12 13:27:12 +02:00
|
|
|
}
|
2017-12-03 21:29:27 +01:00
|
|
|
|
|
|
|
func TestConnectionInterface(t *testing.T) {
|
|
|
|
assert := With(t)
|
|
|
|
|
|
|
|
assert((*Connection)(nil), Implements, (*io.Writer)(nil))
|
|
|
|
assert((*Connection)(nil), Implements, (*io.Reader)(nil))
|
|
|
|
assert((*Connection)(nil), Implements, (*buf.Reader)(nil))
|
|
|
|
}
|