connection_test.go 904 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package kcp_test
  2. import (
  3. "io"
  4. "testing"
  5. "time"
  6. "v2ray.com/core/common/buf"
  7. . "v2ray.com/core/transport/internet/kcp"
  8. . "v2ray.com/ext/assert"
  9. )
  10. type NoOpCloser int
  11. func (NoOpCloser) Close() error {
  12. return nil
  13. }
  14. func TestConnectionReadTimeout(t *testing.T) {
  15. assert := With(t)
  16. conn := NewConnection(ConnMetadata{Conversation: 1}, &KCPPacketWriter{
  17. Writer: buf.DiscardBytes,
  18. }, NoOpCloser(0), &Config{})
  19. conn.SetReadDeadline(time.Now().Add(time.Second))
  20. b := make([]byte, 1024)
  21. nBytes, err := conn.Read(b)
  22. assert(nBytes, Equals, 0)
  23. assert(err, IsNotNil)
  24. conn.Terminate()
  25. }
  26. func TestConnectionInterface(t *testing.T) {
  27. assert := With(t)
  28. assert((*Connection)(nil), Implements, (*io.Writer)(nil))
  29. assert((*Connection)(nil), Implements, (*io.Reader)(nil))
  30. assert((*Connection)(nil), Implements, (*buf.Reader)(nil))
  31. assert((*Connection)(nil), Implements, (*buf.Writer)(nil))
  32. }