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"
|
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-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)
|
2019-02-03 13:46:53 -05:00
|
|
|
if nBytes != 0 || err == nil {
|
|
|
|
t.Error("unexpected read: ", nBytes, err)
|
|
|
|
}
|
2016-10-10 10:50:54 -04:00
|
|
|
|
|
|
|
conn.Terminate()
|
2016-07-12 07:27:12 -04:00
|
|
|
}
|
2017-12-03 15:29:27 -05:00
|
|
|
|
|
|
|
func TestConnectionInterface(t *testing.T) {
|
2019-02-03 13:46:53 -05:00
|
|
|
_ = (io.Writer)(new(Connection))
|
|
|
|
_ = (io.Reader)(new(Connection))
|
|
|
|
_ = (buf.Reader)(new(Connection))
|
|
|
|
_ = (buf.Writer)(new(Connection))
|
2017-12-03 15:29:27 -05:00
|
|
|
}
|