v2ray-core/transport/internet/kcp/connection_test.go

43 lines
904 B
Go
Raw Normal View History

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