fix: kcp 协议内部日志细节
This commit is contained in:
62
cmd/internal/transport/kcp_packet_conn_linux_test.go
Normal file
62
cmd/internal/transport/kcp_packet_conn_linux_test.go
Normal file
@@ -0,0 +1,62 @@
|
||||
//go:build linux
|
||||
|
||||
package transport
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestKCPPendingTXReservationRollbackRestoresSequence(t *testing.T) {
|
||||
conn := &platformKCPPacketConn{
|
||||
kcpPacketConnBase: &kcpPacketConnBase{
|
||||
closed: make(chan struct{}),
|
||||
},
|
||||
pendingTX: make(map[uint32]kcpPendingPacketDebug),
|
||||
}
|
||||
|
||||
conv := uint32(42)
|
||||
txID := conn.reservePendingTX(&net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 9000}, 128, &conv, nil)
|
||||
if txID != 0 {
|
||||
t.Fatalf("reservePendingTX() txID = %d, want 0", txID)
|
||||
}
|
||||
if conn.nextTXID != 1 {
|
||||
t.Fatalf("nextTXID after reserve = %d, want 1", conn.nextTXID)
|
||||
}
|
||||
if _, ok := conn.pendingTX[txID]; !ok {
|
||||
t.Fatal("pendingTX missing reserved record")
|
||||
}
|
||||
|
||||
conn.rollbackPendingTX(txID)
|
||||
|
||||
if conn.nextTXID != 0 {
|
||||
t.Fatalf("nextTXID after rollback = %d, want 0", conn.nextTXID)
|
||||
}
|
||||
if _, ok := conn.pendingTX[txID]; ok {
|
||||
t.Fatal("pendingTX still contains rolled back record")
|
||||
}
|
||||
}
|
||||
|
||||
func TestKCPPendingTXReservationPreservesLaterSequenceOnOutOfOrderRollback(t *testing.T) {
|
||||
conn := &platformKCPPacketConn{
|
||||
kcpPacketConnBase: &kcpPacketConnBase{
|
||||
closed: make(chan struct{}),
|
||||
},
|
||||
pendingTX: make(map[uint32]kcpPendingPacketDebug),
|
||||
}
|
||||
|
||||
first := conn.reservePendingTX(&net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 9000}, 64, nil, nil)
|
||||
second := conn.reservePendingTX(&net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 9001}, 64, nil, nil)
|
||||
if first != 0 || second != 1 {
|
||||
t.Fatalf("reserved tx IDs = %d,%d, want 0,1", first, second)
|
||||
}
|
||||
|
||||
conn.rollbackPendingTX(first)
|
||||
|
||||
if conn.nextTXID != 2 {
|
||||
t.Fatalf("nextTXID after out-of-order rollback = %d, want 2", conn.nextTXID)
|
||||
}
|
||||
if _, ok := conn.pendingTX[second]; !ok {
|
||||
t.Fatal("pendingTX lost later reservation after rollback")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user