1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-18 01:46:06 -04:00
v2fly/transport/internet/kcp/connection_test.go

43 lines
904 B
Go
Raw Normal View History

2016-07-12 07:27:12 -04:00
package kcp_test
import (
2017-12-03 15:29:27 -05:00
"io"
2016-07-12 07:27:12 -04:00
"testing"
"time"
2016-12-08 10:27:41 -05:00
2017-12-03 15:29:27 -05:00
"v2ray.com/core/common/buf"
2016-08-20 14:55:45 -04:00
. "v2ray.com/core/transport/internet/kcp"
2017-10-26 15:44:22 -04:00
. "v2ray.com/ext/assert"
2016-07-12 07:27:12 -04:00
)
2017-12-03 15:29:27 -05:00
type NoOpCloser int
2016-07-12 11:11:36 -04:00
2017-12-03 15:29:27 -05:00
func (NoOpCloser) Close() error {
2016-07-12 11:11:36 -04:00
return nil
}
2016-07-12 07:27:12 -04:00
func TestConnectionReadTimeout(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2016-07-12 07:27:12 -04:00
2017-12-14 17:24:40 -05:00
conn := NewConnection(ConnMetadata{Conversation: 1}, &KCPPacketWriter{
2017-12-03 15:29:27 -05:00
Writer: buf.DiscardBytes,
}, NoOpCloser(0), &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)
2017-10-24 10:15:35 -04:00
assert(nBytes, Equals, 0)
assert(err, IsNotNil)
conn.Terminate()
2016-07-12 07:27:12 -04:00
}
2017-12-03 15:29:27 -05: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))
2017-12-03 17:11:29 -05:00
assert((*Connection)(nil), Implements, (*buf.Writer)(nil))
2017-12-03 15:29:27 -05:00
}