Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to math/rand/v2 #1557

Merged
merged 1 commit into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions coredns/loadbalancer/smooth_weighted_round_robin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ limitations under the License.
package loadbalancer_test

import (
cryptoRand "crypto/rand"
"math/big"
"math/rand"
"time"
"math/rand/v2"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -34,24 +31,12 @@ type server struct {
weight int64
}

//nolint:gosec // This is only used to shuffle the list of resolvers
var randgen = rand.New(rand.NewSource(time.Now().UnixNano()))

var _ = Describe("Smooth Weighted RR", func() {
// Global Vars
var servers []server
var smoothTestingServers []server
var roundRobinServers []server
var lb loadbalancer.Interface
// Helpers
randInt := func() int64 {
maxWeight := int64(20)
rInt, err := cryptoRand.Int(cryptoRand.Reader, big.NewInt(maxWeight))
if err != nil {
return int64(10)
}
return rInt.Int64()
}

addServer := func(s server) {
err := lb.Add(s.name, s.weight)
Expand Down Expand Up @@ -126,18 +111,19 @@ var _ = Describe("Smooth Weighted RR", func() {
{name: "server2", weight: 1},
{name: "server3", weight: 1},
}
maxWeight := int64(20)
servers = []server{
{name: "server1", weight: randInt()},
{name: "server2", weight: randInt()},
{name: "server3", weight: randInt()},
{name: "server1", weight: rand.N(maxWeight)},
{name: "server2", weight: rand.N(maxWeight)},
{name: "server3", weight: rand.N(maxWeight)},
}
roundRobinServers = []server{
{name: "server1", weight: 1},
{name: "server2", weight: 1},
{name: "server3", weight: 1},
}

randgen.Shuffle(len(servers), func(i, j int) { servers[i], servers[j] = servers[j], servers[i] })
rand.Shuffle(len(servers), func(i, j int) { servers[i], servers[j] = servers[j], servers[i] })
})

When("first created", func() {
Expand Down
Loading