2016-07-12 11:27:12 +00:00
|
|
|
package kcp_test
|
|
|
|
|
|
|
|
import (
|
2016-11-27 07:58:31 +00:00
|
|
|
"net"
|
2016-07-12 11:27:12 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
2016-12-08 15:27:41 +00:00
|
|
|
|
2016-08-20 18:55:45 +00:00
|
|
|
"v2ray.com/core/testing/assert"
|
|
|
|
. "v2ray.com/core/transport/internet/kcp"
|
2016-07-12 11:27:12 +00:00
|
|
|
)
|
|
|
|
|
2016-11-27 07:58:31 +00:00
|
|
|
type NoOpConn struct{}
|
2016-07-12 15:11:36 +00:00
|
|
|
|
2016-12-08 15:27:41 +00:00
|
|
|
func (o *NoOpConn) Overhead() int {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2016-11-27 07:58:31 +00:00
|
|
|
func (o *NoOpConn) Write(b []byte) (int, error) {
|
2016-07-12 15:11:36 +00:00
|
|
|
return len(b), nil
|
|
|
|
}
|
|
|
|
|
2016-11-27 07:58:31 +00:00
|
|
|
func (o *NoOpConn) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *NoOpConn) Read([]byte) (int, error) {
|
|
|
|
panic("Should not be called.")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *NoOpConn) LocalAddr() net.Addr {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *NoOpConn) RemoteAddr() net.Addr {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *NoOpConn) SetDeadline(time.Time) error {
|
2016-07-12 15:11:36 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-11-27 07:58:31 +00:00
|
|
|
func (o *NoOpConn) SetReadDeadline(time.Time) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *NoOpConn) SetWriteDeadline(time.Time) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-12-08 15:27:41 +00:00
|
|
|
func (o *NoOpConn) Reset(input func([]Segment)) {}
|
2016-11-27 07:58:31 +00:00
|
|
|
|
2016-07-12 11:27:12 +00:00
|
|
|
func TestConnectionReadTimeout(t *testing.T) {
|
|
|
|
assert := assert.On(t)
|
|
|
|
|
2017-04-07 19:54:40 +00:00
|
|
|
conn := NewConnection(1, &NoOpConn{}, &Config{})
|
2016-07-12 11:27:12 +00:00
|
|
|
conn.SetReadDeadline(time.Now().Add(time.Second))
|
|
|
|
|
|
|
|
b := make([]byte, 1024)
|
|
|
|
nBytes, err := conn.Read(b)
|
|
|
|
assert.Int(nBytes).Equals(0)
|
|
|
|
assert.Error(err).IsNotNil()
|
2016-10-10 14:50:54 +00:00
|
|
|
|
|
|
|
conn.Terminate()
|
2016-07-12 11:27:12 +00:00
|
|
|
}
|