Fix pool to uint from int

This commit is contained in:
PhatPhuckDave
2024-07-23 09:31:26 +02:00
parent f00dcafac4
commit c73a6066c4
3 changed files with 16 additions and 16 deletions

View File

@@ -7,12 +7,12 @@ import (
func TestRetrieveBufferOfRequestedSize(t *testing.T) {
bpm := &BufferPoolManager{
pools: make(map[int]*sync.Pool),
pools: make(map[uint]*sync.Pool),
mu: sync.Mutex{},
}
size := 1024
buffer := bpm.GetBuffer(size)
buffer := bpm.GetBuffer(uint(size))
if buffer == nil {
t.Fatalf("Expected buffer, got nil")
@@ -25,12 +25,12 @@ func TestRetrieveBufferOfRequestedSize(t *testing.T) {
func TestRequestBufferSizeZero(t *testing.T) {
bpm := &BufferPoolManager{
pools: make(map[int]*sync.Pool),
pools: make(map[uint]*sync.Pool),
mu: sync.Mutex{},
}
size := 0
buffer := bpm.GetBuffer(size)
buffer := bpm.GetBuffer(uint(size))
if buffer == nil {
t.Fatalf("Expected buffer, got nil")
@@ -43,7 +43,7 @@ func TestRequestBufferSizeZero(t *testing.T) {
func TestConcurrentAccessToBufferPool(t *testing.T) {
bpm := &BufferPoolManager{
pools: make(map[int]*sync.Pool),
pools: make(map[uint]*sync.Pool),
mu: sync.Mutex{},
}
@@ -55,7 +55,7 @@ func TestConcurrentAccessToBufferPool(t *testing.T) {
wg.Add(1)
go func() {
defer wg.Done()
buffer := bpm.GetBuffer(size)
buffer := bpm.GetBuffer(uint(size))
if buffer == nil {
t.Errorf("Expected buffer, got nil")
}
@@ -70,12 +70,12 @@ func TestConcurrentAccessToBufferPool(t *testing.T) {
func TestGetBufferLockUnlock(t *testing.T) {
bpm := &BufferPoolManager{
pools: make(map[int]*sync.Pool),
pools: make(map[uint]*sync.Pool),
mu: sync.Mutex{},
}
size := 1024
buffer := bpm.GetBuffer(size)
buffer := bpm.GetBuffer(uint(size))
if buffer == nil {
t.Fatalf("Expected buffer, got nil")
@@ -88,12 +88,12 @@ func TestGetBufferLockUnlock(t *testing.T) {
func TestVerifyPoolCreationForNewSizes(t *testing.T) {
bpm := &BufferPoolManager{
pools: make(map[int]*sync.Pool),
pools: make(map[uint]*sync.Pool),
mu: sync.Mutex{},
}
size := 512
buffer := bpm.GetBuffer(size)
buffer := bpm.GetBuffer(uint(size))
if buffer == nil {
t.Fatalf("Expected buffer, got nil")
@@ -106,12 +106,12 @@ func TestVerifyPoolCreationForNewSizes(t *testing.T) {
func TestBufferPoolManagerGetBuffer(t *testing.T) {
bpm := &BufferPoolManager{
pools: make(map[int]*sync.Pool),
pools: make(map[uint]*sync.Pool),
mu: sync.Mutex{},
}
size := 1024
buffer := bpm.GetBuffer(size)
buffer := bpm.GetBuffer(uint(size))
if buffer == nil {
t.Fatalf("Expected buffer, got nil")
@@ -124,13 +124,13 @@ func TestBufferPoolManagerGetBuffer(t *testing.T) {
func TestGetBufferWithMultipleSizes(t *testing.T) {
bpm := &BufferPoolManager{
pools: make(map[int]*sync.Pool),
pools: make(map[uint]*sync.Pool),
mu: sync.Mutex{},
}
sizes := []int{512, 1024, 2048}
for _, size := range sizes {
buffer := bpm.GetBuffer(size)
buffer := bpm.GetBuffer(uint(size))
if buffer == nil {
t.Fatalf("Expected buffer for size %d, got nil", size)

View File

@@ -3,6 +3,6 @@ package pdu
import "sync"
var ByteBufferPool = &BufferPoolManager{
pools: make(map[int]*sync.Pool),
pools: make(map[uint]*sync.Pool),
mu: sync.Mutex{},
}

View File

@@ -27,7 +27,7 @@ type (
)
func (p *PDU_HEADER) Encode() (*[]uint8, error) {
buf := ByteBufferPool.GetBuffer(int(p.Size()))
buf := ByteBufferPool.GetBuffer(uint(p.Size()))
err := p.EncodeInto(buf)
return buf, err
}