1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-06 18:28:00 -05:00
v2fly/transport/internet/kcp/connection_test.go

74 lines
1.3 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"
2016-11-27 02:58:31 -05:00
"v2ray.com/core/transport/internet/internal"
2016-08-20 14:55:45 -04:00
. "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
}
2017-01-01 16:12:44 -05:00
func (o *NoOpConn) Id() internal.ConnectionID {
return internal.ConnectionID{}
2016-11-27 02:58:31 -05:00
}
2016-12-08 10:27:41 -05:00
func (o *NoOpConn) Reset(input func([]Segment)) {}
2016-11-27 02:58:31 -05:00
type NoOpRecycler struct{}
2017-01-01 16:12:44 -05:00
func (o *NoOpRecycler) Put(internal.ConnectionID, net.Conn) {}
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)
2016-12-08 10:27:41 -05:00
conn := NewConnection(1, &NoOpConn{}, &NoOpRecycler{}, &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
}