connection_test.go 767 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. )
  9. type NoOpCloser int
  10. func (NoOpCloser) Close() error {
  11. return nil
  12. }
  13. func TestConnectionReadTimeout(t *testing.T) {
  14. conn := NewConnection(ConnMetadata{Conversation: 1}, &KCPPacketWriter{
  15. Writer: buf.DiscardBytes,
  16. }, NoOpCloser(0), &Config{})
  17. conn.SetReadDeadline(time.Now().Add(time.Second))
  18. b := make([]byte, 1024)
  19. nBytes, err := conn.Read(b)
  20. if nBytes != 0 || err == nil {
  21. t.Error("unexpected read: ", nBytes, err)
  22. }
  23. conn.Terminate()
  24. }
  25. func TestConnectionInterface(t *testing.T) {
  26. _ = (io.Writer)(new(Connection))
  27. _ = (io.Reader)(new(Connection))
  28. _ = (buf.Reader)(new(Connection))
  29. _ = (buf.Writer)(new(Connection))
  30. }