github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/transport/internet/kcp/connection_test.go (about)

     1  package kcp_test
     2  
     3  import (
     4  	"io"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/v2fly/v2ray-core/v5/common/buf"
     9  	. "github.com/v2fly/v2ray-core/v5/transport/internet/kcp"
    10  )
    11  
    12  type NoOpCloser int
    13  
    14  func (NoOpCloser) Close() error {
    15  	return nil
    16  }
    17  
    18  func TestConnectionReadTimeout(t *testing.T) {
    19  	conn := NewConnection(ConnMetadata{Conversation: 1}, &KCPPacketWriter{
    20  		Writer: buf.DiscardBytes,
    21  	}, NoOpCloser(0), &Config{})
    22  	conn.SetReadDeadline(time.Now().Add(time.Second))
    23  
    24  	b := make([]byte, 1024)
    25  	nBytes, err := conn.Read(b)
    26  	if nBytes != 0 || err == nil {
    27  		t.Error("unexpected read: ", nBytes, err)
    28  	}
    29  
    30  	conn.Terminate()
    31  }
    32  
    33  func TestConnectionInterface(t *testing.T) {
    34  	_ = (io.Writer)(new(Connection))
    35  	_ = (io.Reader)(new(Connection))
    36  	_ = (buf.Reader)(new(Connection))
    37  	_ = (buf.Writer)(new(Connection))
    38  }