From 837b47244141e2977d4a2bf5e8d1b4be4492bddd Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Mon, 12 Jun 2023 10:42:14 -0600 Subject: [PATCH] e2e: GetRandomIPAddress(): parallelize Fixes: #18855 Signed-off-by: Ed Santiago --- test/e2e/common_test.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index 697522b2f0..12b2b0e40f 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -484,11 +484,14 @@ func GetPortLock(port string) *lockfile.LockFile { func GetRandomIPAddress() string { // To avoid IP collisions of initialize random seed for random IP addresses rng := rand.New(rand.NewSource(time.Now().UnixNano())) - // Add GinkgoParallelProcess() on top of the IP address - // in case of the same random seed - ip3 := strconv.Itoa(rng.Intn(230) + GinkgoParallelProcess()) - ip4 := strconv.Itoa(rng.Intn(230) + GinkgoParallelProcess()) - return "10.88." + ip3 + "." + ip4 + + nProcs := GinkgoT().ParallelTotal() + myProc := GinkgoT().ParallelProcess() - 1 + + // 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