test/e2e: allocate dynamic ports outside whitelist ranges in server whitelist test (#5268)

This commit is contained in:
fatedier
2026-03-30 00:21:30 +08:00
committed by GitHub
parent 061c141756
commit 31e271939b
3 changed files with 41 additions and 12 deletions

View File

@@ -241,6 +241,31 @@ func (f *Framework) AllocPort() int {
return port
}
func (f *Framework) AllocPortExcludingRanges(ranges ...[2]int) int {
for range 1000 {
port := f.portAllocator.Get()
ExpectTrue(port > 0, "alloc port failed")
inExcludedRange := false
for _, portRange := range ranges {
if port >= portRange[0] && port <= portRange[1] {
inExcludedRange = true
break
}
}
if inExcludedRange {
f.portAllocator.Release(port)
continue
}
f.allocatedPorts = append(f.allocatedPorts, port)
return port
}
Failf("alloc port outside excluded ranges failed")
return 0
}
func (f *Framework) ReleasePort(port int) {
f.portAllocator.Release(port)
}