1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-23 10:37:09 -05:00
v2fly/transport/internet/kcp/connection_test.go

65 lines
1.1 KiB
Go
Raw Normal View History

2016-07-12 07:27:12 -04:00
package kcp_test
import (
2016-11-27 02:58:31 -05:00
"net"
2016-07-12 07:27:12 -04:00
"testing"
"time"
2016-12-08 10:27:41 -05:00
2016-08-20 14:55:45 -04:00
"v2ray.com/core/testing/assert"
. "v2ray.com/core/transport/internet/kcp"
2016-07-12 07:27:12 -04:00
)
2016-11-27 02:58:31 -05:00
type NoOpConn struct{}
2016-07-12 11:11:36 -04:00
2016-12-08 10:27:41 -05:00
func (o *NoOpConn) Overhead() int {
return 0
}
2016-11-27 02:58:31 -05:00
func (o *NoOpConn) Write(b []byte) (int, error) {
2016-07-12 11:11:36 -04:00
return len(b), nil
}
2016-11-27 02:58:31 -05: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 11:11:36 -04:00
return nil
}
2016-11-27 02:58:31 -05:00
func (o *NoOpConn) SetReadDeadline(time.Time) error {
return nil
}
func (o *NoOpConn) SetWriteDeadline(time.Time) error {
return nil
}
2016-12-08 10:27:41 -05:00
func (o *NoOpConn) Reset(input func([]Segment)) {}
2016-11-27 02:58:31 -05:00
2016-07-12 07:27:12 -04:00
func TestConnectionReadTimeout(t *testing.T) {
assert := assert.On(t)
conn := NewConnection(1, &NoOpConn{}, &Config{})
2016-07-12 07:27:12 -04: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()
conn.Terminate()
2016-07-12 07:27:12 -04:00
}