netutil: improve port allocation (#5485)

This commit is contained in:
Caleb Doxsey 2025-02-19 09:45:21 -07:00 committed by GitHub
parent fbd1f34110
commit 4b95eda51e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 54 additions and 5 deletions

View file

@ -0,0 +1,24 @@
package netutil_test
import (
"testing"
"github.com/minio/minio-go/v7/pkg/set"
"github.com/stretchr/testify/assert"
"github.com/pomerium/pomerium/pkg/netutil"
)
func TestAllocatePorts(t *testing.T) {
t.Parallel()
seen := set.NewStringSet()
for i := 0; i < 100; i++ {
ports, err := netutil.AllocatePorts(3)
assert.NoError(t, err)
for _, p := range ports {
assert.False(t, seen.Contains(p), "should not re-use ports")
seen.Add(p)
}
}
}