Merge pull request #18858 from edsantiago/parallelize_getrandomip

e2e: GetRandomIPAddress(): parallelize
This commit is contained in:
OpenShift Merge Robot
2023-06-13 05:13:13 -04:00
committed by GitHub

View File

@ -484,11 +484,14 @@ func GetPortLock(port string) *lockfile.LockFile {
func GetRandomIPAddress() string { func GetRandomIPAddress() string {
// To avoid IP collisions of initialize random seed for random IP addresses // To avoid IP collisions of initialize random seed for random IP addresses
rng := rand.New(rand.NewSource(time.Now().UnixNano())) rng := rand.New(rand.NewSource(time.Now().UnixNano()))
// Add GinkgoParallelProcess() on top of the IP address
// in case of the same random seed nProcs := GinkgoT().ParallelTotal()
ip3 := strconv.Itoa(rng.Intn(230) + GinkgoParallelProcess()) myProc := GinkgoT().ParallelProcess() - 1
ip4 := strconv.Itoa(rng.Intn(230) + GinkgoParallelProcess())
return "10.88." + ip3 + "." + ip4 // 10.88.255 is unlikely to be used by CNI or netavark.
// Last octet .0 - .254, and will be unique to this ginkgo process.
ip4 := strconv.Itoa(rng.Intn((255-nProcs)/nProcs)*nProcs + myProc)
return "10.88.255." + ip4
} }
// RunTopContainer runs a simple container in the background that // RunTopContainer runs a simple container in the background that