Files
EdgeNode/internal/conns/map_test_test.go
GoEdgeLab c19be78e0d v1.4.1
2024-07-27 15:42:50 +08:00

69 lines
1.3 KiB
Go

// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package conns_test
import (
"net"
"runtime"
"testing"
"time"
"github.com/TeaOSLab/EdgeNode/internal/conns"
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
)
type testConn struct {
net.Conn
addr net.Addr
}
func (this *testConn) Read(b []byte) (n int, err error) {
return
}
func (this *testConn) Write(b []byte) (n int, err error) {
return
}
func (this *testConn) Close() error {
return nil
}
func (this *testConn) LocalAddr() net.Addr {
return &net.TCPAddr{
IP: net.ParseIP(testutils.RandIP()),
Port: 1234,
}
}
func (this *testConn) RemoteAddr() net.Addr {
if this.addr != nil {
return this.addr
}
this.addr = &net.TCPAddr{
IP: net.ParseIP(testutils.RandIP()),
Port: 1234,
}
return this.addr
}
func (this *testConn) SetDeadline(t time.Time) error {
return nil
}
func (this *testConn) SetReadDeadline(t time.Time) error {
return nil
}
func (this *testConn) SetWriteDeadline(t time.Time) error {
return nil
}
func BenchmarkMap_Add(b *testing.B) {
runtime.GOMAXPROCS(512)
var m = conns.NewMap()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
var conn = &testConn{}
m.Add(conn)
m.Remove(conn)
}
})
}