Skip to content

Commit

Permalink
increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fish-tennis committed Jun 30, 2023
1 parent e308e72 commit 8eabbdc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
18 changes: 9 additions & 9 deletions tcp_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,15 @@ func (this *TcpConnection) createRecvBuffer() *RingBuffer {
return NewRingBuffer(int(ringBufferSize))
}

// 发包RingBuffer
func (this *TcpConnection) GetSendBuffer() *RingBuffer {
return this.sendBuffer
}

// 收包RingBuffer
func (this *TcpConnection) GetRecvBuffer() *RingBuffer {
return this.recvBuffer
}
//// 发包RingBuffer
//func (this *TcpConnection) GetSendBuffer() *RingBuffer {
// return this.sendBuffer
//}
//
//// 收包RingBuffer
//func (this *TcpConnection) GetRecvBuffer() *RingBuffer {
// return this.recvBuffer
//}

// LocalAddr returns the local network address.
func (this *TcpConnection) LocalAddr() net.Addr {
Expand Down
11 changes: 6 additions & 5 deletions tcp_connection_simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestTcpConnectionSimple(t *testing.T) {
}
listenAddress := "127.0.0.1:10002"
codec := NewSimpleProtoCodec()
codec.Register(PacketCommand(pb.CmdTest_Cmd_HeartBeat), new(pb.HeartBeatRes))
codec.Register(PacketCommand(pb.CmdTest_Cmd_TestMessage), new(pb.TestMessage))
codec.Register(PacketCommand(10086), nil)

Expand All @@ -50,7 +51,7 @@ func TestTcpConnectionSimple(t *testing.T) {
connectorConnectionConfig := ConnectionConfig{
SendPacketCacheCap: 100,
MaxPacketSize: 60,
RecvTimeout: 5,
RecvTimeout: 3,
HeartBeatInterval: 2,
WriteTimeout: 1,
}
Expand All @@ -59,7 +60,7 @@ func TestTcpConnectionSimple(t *testing.T) {
connectionHandler, nil, func(config *ConnectionConfig, codec Codec, handler ConnectionHandler) Connection {
return NewTcpConnectionSimple(config, codec, handler)
})
for i := 0; i < 2; i++ {
for i := 0; i < 10; i++ {
netMgr.NewConnectorCustom(ctx, listenAddress, &connectorConnectionConfig, codec,
connectionHandler, nil, func(config *ConnectionConfig, codec Codec, handler ConnectionHandler) Connection {
return NewTcpConnectionSimple(config, codec, handler)
Expand All @@ -75,14 +76,14 @@ func TestTcpConnectionSimple(t *testing.T) {
return true
})
listener.Broadcast(NewProtoPacketWithData(10086, []byte("test")))

time.Sleep(7 * time.Second)
listener.GetConnection(1)
// test a wrong packet
listener.(*TcpListener).RangeConnections(func(conn Connection) bool {
conn.SendPacket(NewDataPacket([]byte("wrong packet test")))
return false
})

time.Sleep(7 * time.Second)
listener.GetConnection(1)
time.Sleep(1 * time.Second)
listener.Close()

Expand Down

0 comments on commit 8eabbdc

Please sign in to comment.