connection_test.go 652 B

123456789101112131415161718192021222324252627282930313233
  1. package kcp_test
  2. import (
  3. "testing"
  4. "time"
  5. "v2ray.com/core/testing/assert"
  6. . "v2ray.com/core/transport/internet/kcp"
  7. )
  8. type NoOpWriteCloser struct{}
  9. func (this *NoOpWriteCloser) Write(b []byte) (int, error) {
  10. return len(b), nil
  11. }
  12. func (this *NoOpWriteCloser) Close() error {
  13. return nil
  14. }
  15. func TestConnectionReadTimeout(t *testing.T) {
  16. assert := assert.On(t)
  17. conn := NewConnection(1, &NoOpWriteCloser{}, nil, nil, NewSimpleAuthenticator(), &Config{})
  18. conn.SetReadDeadline(time.Now().Add(time.Second))
  19. b := make([]byte, 1024)
  20. nBytes, err := conn.Read(b)
  21. assert.Int(nBytes).Equals(0)
  22. assert.Error(err).IsNotNil()
  23. conn.Terminate()
  24. }