1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-21 04:34:15 -04:00
v2fly/transport/internet/kcp/connection_test.go

34 lines
652 B
Go
Raw Normal View History

2016-07-12 07:27:12 -04:00
package kcp_test
import (
"testing"
"time"
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-07-12 11:11:36 -04:00
type NoOpWriteCloser struct{}
func (this *NoOpWriteCloser) Write(b []byte) (int, error) {
return len(b), nil
}
func (this *NoOpWriteCloser) Close() error {
return nil
}
2016-07-12 07:27:12 -04:00
func TestConnectionReadTimeout(t *testing.T) {
assert := assert.On(t)
2016-10-02 17:43:58 -04:00
conn := NewConnection(1, &NoOpWriteCloser{}, nil, nil, NewSimpleAuthenticator(), &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
}