proxy-pool/internal/domain/upstream/pool_test.go

45 lines
1.4 KiB
Go

package upstream
import (
"testing"
"time"
proxyDomain "proxy-pool/internal/domain/proxy"
)
func TestInventoryAvailableSlotsUsesOnlyAllocatableCapacity(t *testing.T) {
now := time.Date(2026, 7, 28, 12, 0, 0, 0, time.UTC)
inventory := Inventory{Proxies: []ProxyCapacity{
{State: proxyDomain.StateAvailable, ExpiresAt: now.Add(time.Minute), Max: 10, Active: 3, Reserved: 2},
{State: proxyDomain.StateAvailable, ExpiresAt: now.Add(5 * time.Second), Max: 10},
{State: proxyDomain.StateChecking, ExpiresAt: now.Add(time.Minute), Max: 10},
{State: proxyDomain.StateAvailable, ExpiresAt: now.Add(time.Minute), Max: 2, Active: 3},
}}
if got := inventory.AvailableSlots(now, 10*time.Second); got != 5 {
t.Fatalf("AvailableSlots() = %d, want 5", got)
}
}
func TestInventoryFetchAllowanceUsesManagedPoolCapacity(t *testing.T) {
inventory := Inventory{
Proxies: []ProxyCapacity{
{State: proxyDomain.StateFetched},
{State: proxyDomain.StateChecking},
{State: proxyDomain.StateAvailable},
{State: proxyDomain.StateSuspect},
{State: proxyDomain.StateDraining},
{State: proxyDomain.StateExtracted},
},
PendingExpected: 2,
MaxSize: 10,
}
if got := inventory.ManagedCount(); got != 7 {
t.Fatalf("ManagedCount() = %d, want 7", got)
}
if got := inventory.FetchAllowance(10); got != 3 {
t.Fatalf("FetchAllowance() = %d, want 3 from pool size", got)
}
}