From 52d7f6af60d427c1588e8223b07318795caace84 Mon Sep 17 00:00:00 2001 From: Marco Ferrer <35935108+marcoferrer@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:43:58 -0400 Subject: [PATCH] multiple: switch to math/rand/v2 (#7711) Co-authored-by: Arvind Bright --- balancer/endpointsharding/endpointsharding.go | 5 +++-- balancer/grpclb/grpclb_picker.go | 6 +++--- balancer/leastrequest/leastrequest.go | 2 +- balancer/pickfirst/pickfirst.go | 2 +- balancer/rls/internal/adaptive/adaptive.go | 6 +++--- balancer/roundrobin/roundrobin.go | 4 ++-- balancer/weightedroundrobin/balancer.go | 2 +- benchmark/benchmain/main.go | 6 +++--- benchmark/benchmark.go | 4 ++-- benchmark/stats/curve.go | 4 ++-- benchmark/worker/benchmark_client.go | 2 +- examples/features/debugging/server/main.go | 4 ++-- examples/features/xds/server/main.go | 2 +- examples/route_guide/client/client.go | 13 ++++++------- internal/backoff/backoff.go | 2 +- internal/resolver/dns/dns_resolver.go | 4 ++-- internal/serviceconfig/duration_test.go | 2 +- internal/transport/http2_server.go | 4 ++-- internal/wrr/random.go | 8 ++++---- internal/wrr/wrr_test.go | 8 ++++---- interop/stress/client/main.go | 4 ++-- stream.go | 4 ++-- xds/googledirectpath/googlec2p.go | 2 +- xds/internal/balancer/outlierdetection/balancer.go | 6 +++--- .../balancer/ringhash/e2e/ringhash_balancer_test.go | 2 +- xds/internal/httpfilter/fault/fault.go | 4 ++-- xds/internal/httpfilter/fault/fault_test.go | 4 ++-- xds/internal/resolver/serviceconfig.go | 2 +- xds/internal/resolver/xds_resolver.go | 2 +- xds/internal/xdsclient/xdsresource/matcher.go | 8 ++++---- xds/internal/xdsclient/xdsresource/matcher_test.go | 10 +++++----- 31 files changed, 69 insertions(+), 69 deletions(-) diff --git a/balancer/endpointsharding/endpointsharding.go b/balancer/endpointsharding/endpointsharding.go index 8425ddea56d0..9238d3278204 100644 --- a/balancer/endpointsharding/endpointsharding.go +++ b/balancer/endpointsharding/endpointsharding.go @@ -28,10 +28,11 @@ package endpointsharding import ( "encoding/json" "errors" - "math/rand" "sync" "sync/atomic" + rand "math/rand/v2" + "google.golang.org/grpc/balancer" "google.golang.org/grpc/balancer/base" "google.golang.org/grpc/connectivity" @@ -225,7 +226,7 @@ func (es *endpointSharding) updateState() { p := &pickerWithChildStates{ pickers: pickers, childStates: childStates, - next: uint32(rand.Intn(len(pickers))), + next: uint32(rand.IntN(len(pickers))), } es.cc.UpdateState(balancer.State{ ConnectivityState: aggState, diff --git a/balancer/grpclb/grpclb_picker.go b/balancer/grpclb/grpclb_picker.go index 671bc663fcb0..9ff07522d786 100644 --- a/balancer/grpclb/grpclb_picker.go +++ b/balancer/grpclb/grpclb_picker.go @@ -19,7 +19,7 @@ package grpclb import ( - "math/rand" + rand "math/rand/v2" "sync" "sync/atomic" @@ -112,7 +112,7 @@ type rrPicker struct { func newRRPicker(readySCs []balancer.SubConn) *rrPicker { return &rrPicker{ subConns: readySCs, - subConnsNext: rand.Intn(len(readySCs)), + subConnsNext: rand.IntN(len(readySCs)), } } @@ -147,7 +147,7 @@ func newLBPicker(serverList []*lbpb.Server, readySCs []balancer.SubConn, stats * return &lbPicker{ serverList: serverList, subConns: readySCs, - subConnsNext: rand.Intn(len(readySCs)), + subConnsNext: rand.IntN(len(readySCs)), stats: stats, } } diff --git a/balancer/leastrequest/leastrequest.go b/balancer/leastrequest/leastrequest.go index ddd9bd269bf4..6dede1a40b70 100644 --- a/balancer/leastrequest/leastrequest.go +++ b/balancer/leastrequest/leastrequest.go @@ -22,7 +22,7 @@ package leastrequest import ( "encoding/json" "fmt" - "math/rand" + rand "math/rand/v2" "sync/atomic" "google.golang.org/grpc/balancer" diff --git a/balancer/pickfirst/pickfirst.go b/balancer/pickfirst/pickfirst.go index e069346a7565..ea8899818c22 100644 --- a/balancer/pickfirst/pickfirst.go +++ b/balancer/pickfirst/pickfirst.go @@ -23,7 +23,7 @@ import ( "encoding/json" "errors" "fmt" - "math/rand" + rand "math/rand/v2" "google.golang.org/grpc/balancer" "google.golang.org/grpc/balancer/pickfirst/internal" diff --git a/balancer/rls/internal/adaptive/adaptive.go b/balancer/rls/internal/adaptive/adaptive.go index 8b1786043486..6249948ede72 100644 --- a/balancer/rls/internal/adaptive/adaptive.go +++ b/balancer/rls/internal/adaptive/adaptive.go @@ -20,15 +20,15 @@ package adaptive import ( - "math/rand" + rand "math/rand/v2" "sync" "time" ) // For overriding in unittests. var ( - timeNowFunc = func() time.Time { return time.Now() } - randFunc = func() float64 { return rand.Float64() } + timeNowFunc = time.Now + randFunc = rand.Float64 ) const ( diff --git a/balancer/roundrobin/roundrobin.go b/balancer/roundrobin/roundrobin.go index 260255d31b6a..80a42d22510c 100644 --- a/balancer/roundrobin/roundrobin.go +++ b/balancer/roundrobin/roundrobin.go @@ -22,7 +22,7 @@ package roundrobin import ( - "math/rand" + rand "math/rand/v2" "sync/atomic" "google.golang.org/grpc/balancer" @@ -60,7 +60,7 @@ func (*rrPickerBuilder) Build(info base.PickerBuildInfo) balancer.Picker { // Start at a random index, as the same RR balancer rebuilds a new // picker when SubConn states change, and we don't want to apply excess // load to the first server in the list. - next: uint32(rand.Intn(len(scs))), + next: uint32(rand.IntN(len(scs))), } } diff --git a/balancer/weightedroundrobin/balancer.go b/balancer/weightedroundrobin/balancer.go index 1ea9eba4c894..a0511772d2fa 100644 --- a/balancer/weightedroundrobin/balancer.go +++ b/balancer/weightedroundrobin/balancer.go @@ -23,7 +23,7 @@ import ( "encoding/json" "errors" "fmt" - "math/rand" + rand "math/rand/v2" "sync" "sync/atomic" "time" diff --git a/benchmark/benchmain/main.go b/benchmark/benchmain/main.go index 79004f42cba1..a298108786e9 100644 --- a/benchmark/benchmain/main.go +++ b/benchmark/benchmain/main.go @@ -47,7 +47,7 @@ import ( "fmt" "io" "log" - "math/rand" + rand "math/rand/v2" "net" "os" "reflect" @@ -283,7 +283,7 @@ func unconstrainedStreamBenchmark(start startFunc, stop ucStopFunc, bf stats.Fea defer wg.Done() for { if maxSleep > 0 { - time.Sleep(time.Duration(rand.Intn(maxSleep))) + time.Sleep(time.Duration(rand.IntN(maxSleep))) } t := time.Now() if t.After(bmEnd) { @@ -574,7 +574,7 @@ func runBenchmark(caller rpcCallFunc, start startFunc, stop stopFunc, bf stats.F defer wg.Done() for { if maxSleep > 0 { - time.Sleep(time.Duration(rand.Intn(maxSleep))) + time.Sleep(time.Duration(rand.IntN(maxSleep))) } t := time.Now() if t.After(bmEnd) { diff --git a/benchmark/benchmark.go b/benchmark/benchmark.go index 07c8c9db6651..0d4558f4ec80 100644 --- a/benchmark/benchmark.go +++ b/benchmark/benchmark.go @@ -26,7 +26,7 @@ import ( "fmt" "io" "log" - "math/rand" + rand "math/rand/v2" "net" "strconv" "time" @@ -187,7 +187,7 @@ func (s *testServer) UnconstrainedStreamingCall(stream testgrpc.BenchmarkService go func() { for { if maxSleep > 0 { - time.Sleep(time.Duration(rand.Intn(maxSleep))) + time.Sleep(time.Duration(rand.IntN(maxSleep))) } var err error if preloadMsgSize > 0 { diff --git a/benchmark/stats/curve.go b/benchmark/stats/curve.go index 124183dac2ea..801403169d19 100644 --- a/benchmark/stats/curve.go +++ b/benchmark/stats/curve.go @@ -24,7 +24,7 @@ import ( "encoding/hex" "fmt" "math" - "math/rand" + rand "math/rand/v2" "os" "sort" "strconv" @@ -74,7 +74,7 @@ func (pcr *payloadCurveRange) chooseRandom() int { return int(pcr.from) } - return int(rand.Int31n(pcr.to-pcr.from+1) + pcr.from) + return int(rand.Int32N(pcr.to-pcr.from+1) + pcr.from) } // sha256file is a helper function that returns a hex string matching the diff --git a/benchmark/worker/benchmark_client.go b/benchmark/worker/benchmark_client.go index d3d04cd012c3..45f5b2e9ec37 100644 --- a/benchmark/worker/benchmark_client.go +++ b/benchmark/worker/benchmark_client.go @@ -22,7 +22,7 @@ import ( "context" "flag" "math" - "math/rand" + rand "math/rand/v2" "runtime" "sync" "time" diff --git a/examples/features/debugging/server/main.go b/examples/features/debugging/server/main.go index 5dd31af9cedc..21c15e8718fb 100644 --- a/examples/features/debugging/server/main.go +++ b/examples/features/debugging/server/main.go @@ -23,7 +23,7 @@ package main import ( "context" "log" - "math/rand" + rand "math/rand/v2" "net" "time" @@ -55,7 +55,7 @@ type slowServer struct { // SayHello implements helloworld.GreeterServer func (s *slowServer) SayHello(_ context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { // Delay 100ms ~ 200ms before replying - time.Sleep(time.Duration(100+rand.Intn(100)) * time.Millisecond) + time.Sleep(time.Duration(100+rand.IntN(100)) * time.Millisecond) return &pb.HelloReply{Message: "Hello " + in.Name}, nil } diff --git a/examples/features/xds/server/main.go b/examples/features/xds/server/main.go index 9f08e69932f7..c4a276844822 100644 --- a/examples/features/xds/server/main.go +++ b/examples/features/xds/server/main.go @@ -25,7 +25,7 @@ import ( "flag" "fmt" "log" - "math/rand" + rand "math/rand/v2" "net" "os" diff --git a/examples/route_guide/client/client.go b/examples/route_guide/client/client.go index 49c80932f96d..57f868af2e35 100644 --- a/examples/route_guide/client/client.go +++ b/examples/route_guide/client/client.go @@ -27,7 +27,7 @@ import ( "flag" "io" "log" - "math/rand" + rand "math/rand/v2" "time" "google.golang.org/grpc" @@ -81,11 +81,10 @@ func printFeatures(client pb.RouteGuideClient, rect *pb.Rectangle) { // runRecordRoute sends a sequence of points to server and expects to get a RouteSummary from server. func runRecordRoute(client pb.RouteGuideClient) { // Create a random number of random points - r := rand.New(rand.NewSource(time.Now().UnixNano())) - pointCount := int(r.Int31n(100)) + 2 // Traverse at least two points + pointCount := int(rand.Int32N(100)) + 2 // Traverse at least two points var points []*pb.Point for i := 0; i < pointCount; i++ { - points = append(points, randomPoint(r)) + points = append(points, randomPoint()) } log.Printf("Traversing %d points.", len(points)) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) @@ -146,9 +145,9 @@ func runRouteChat(client pb.RouteGuideClient) { <-waitc } -func randomPoint(r *rand.Rand) *pb.Point { - lat := (r.Int31n(180) - 90) * 1e7 - long := (r.Int31n(360) - 180) * 1e7 +func randomPoint() *pb.Point { + lat := (rand.Int32N(180) - 90) * 1e7 + long := (rand.Int32N(360) - 180) * 1e7 return &pb.Point{Latitude: lat, Longitude: long} } diff --git a/internal/backoff/backoff.go b/internal/backoff/backoff.go index b15cf482d292..b6ae7f258505 100644 --- a/internal/backoff/backoff.go +++ b/internal/backoff/backoff.go @@ -25,7 +25,7 @@ package backoff import ( "context" "errors" - "math/rand" + rand "math/rand/v2" "time" grpcbackoff "google.golang.org/grpc/backoff" diff --git a/internal/resolver/dns/dns_resolver.go b/internal/resolver/dns/dns_resolver.go index 8691698ef223..cc5d5e05c010 100644 --- a/internal/resolver/dns/dns_resolver.go +++ b/internal/resolver/dns/dns_resolver.go @@ -24,7 +24,7 @@ import ( "context" "encoding/json" "fmt" - "math/rand" + rand "math/rand/v2" "net" "os" "strconv" @@ -425,7 +425,7 @@ func chosenByPercentage(a *int) bool { if a == nil { return true } - return rand.Intn(100)+1 <= *a + return rand.IntN(100)+1 <= *a } func canaryingSC(js string) string { diff --git a/internal/serviceconfig/duration_test.go b/internal/serviceconfig/duration_test.go index b03a4508b4ea..82c0dcdce2a8 100644 --- a/internal/serviceconfig/duration_test.go +++ b/internal/serviceconfig/duration_test.go @@ -21,7 +21,7 @@ package serviceconfig import ( "fmt" "math" - "math/rand" + rand "math/rand/v2" "strings" "testing" "time" diff --git a/internal/transport/http2_server.go b/internal/transport/http2_server.go index 584b50fe5530..279cd5ccb1b4 100644 --- a/internal/transport/http2_server.go +++ b/internal/transport/http2_server.go @@ -25,7 +25,7 @@ import ( "fmt" "io" "math" - "math/rand" + rand "math/rand/v2" "net" "net/http" "strconv" @@ -1455,7 +1455,7 @@ func getJitter(v time.Duration) time.Duration { } // Generate a jitter between +/- 10% of the value. r := int64(v / 10) - j := rand.Int63n(2*r) - r + j := rand.Int64N(2*r) - r return time.Duration(j) } diff --git a/internal/wrr/random.go b/internal/wrr/random.go index 3f611a35059a..0913ed676493 100644 --- a/internal/wrr/random.go +++ b/internal/wrr/random.go @@ -19,7 +19,7 @@ package wrr import ( "fmt" - "math/rand" + rand "math/rand/v2" "sort" ) @@ -46,19 +46,19 @@ func NewRandom() WRR { return &randomWRR{} } -var randInt63n = rand.Int63n +var randInt64n = rand.Int64N func (rw *randomWRR) Next() (item any) { if len(rw.items) == 0 { return nil } if rw.equalWeights { - return rw.items[randInt63n(int64(len(rw.items)))].item + return rw.items[randInt64n(int64(len(rw.items)))].item } sumOfWeights := rw.items[len(rw.items)-1].accumulatedWeight // Random number in [0, sumOfWeights). - randomWeight := randInt63n(sumOfWeights) + randomWeight := randInt64n(sumOfWeights) // Item's accumulated weights are in ascending order, because item's weight >= 0. // Binary search rw.items to find first item whose accumulatedWeight > randomWeight // The return i is guaranteed to be in range [0, len(rw.items)) because randomWeight < last item's accumulatedWeight diff --git a/internal/wrr/wrr_test.go b/internal/wrr/wrr_test.go index 7ede1fff902e..4a7d81eb1f95 100644 --- a/internal/wrr/wrr_test.go +++ b/internal/wrr/wrr_test.go @@ -20,7 +20,7 @@ package wrr import ( "errors" "math" - "math/rand" + rand "math/rand/v2" "strconv" "testing" @@ -146,7 +146,7 @@ func BenchmarkRandomWRRNext(b *testing.B) { w := NewRandom() var sumOfWeights int64 for i := 0; i < n; i++ { - weight := rand.Int63n(maxWeight + 1) + weight := rand.Int64N(maxWeight + 1) w.Add(i, weight) sumOfWeights += weight } @@ -188,6 +188,6 @@ func BenchmarkRandomWRRNext(b *testing.B) { } func init() { - r := rand.New(rand.NewSource(0)) - randInt63n = r.Int63n + r := rand.New(rand.NewPCG(0, 0)) + randInt64n = r.Int64N } diff --git a/interop/stress/client/main.go b/interop/stress/client/main.go index 2defe15d9cb1..8b22716bf0d4 100644 --- a/interop/stress/client/main.go +++ b/interop/stress/client/main.go @@ -23,7 +23,7 @@ import ( "context" "flag" "fmt" - "math/rand" + rand "math/rand/v2" "net" "os" "strconv" @@ -130,7 +130,7 @@ func newWeightedRandomTestSelector(tests []testCaseWithWeight) *weightedRandomTe } func (selector weightedRandomTestSelector) getNextTest() string { - random := rand.Intn(selector.totalWeight) + random := rand.IntN(selector.totalWeight) var weightSofar int for _, test := range selector.tests { weightSofar += test.weight diff --git a/stream.go b/stream.go index bb2b2a216ce2..b2d82c364d7d 100644 --- a/stream.go +++ b/stream.go @@ -23,7 +23,7 @@ import ( "errors" "io" "math" - "math/rand" + rand "math/rand/v2" "strconv" "sync" "time" @@ -710,7 +710,7 @@ func (a *csAttempt) shouldRetry(err error) (bool, error) { if max := float64(rp.MaxBackoff); cur > max { cur = max } - dur = time.Duration(rand.Int63n(int64(cur))) + dur = time.Duration(rand.Int64N(int64(cur))) cs.numRetriesSincePushback++ } diff --git a/xds/googledirectpath/googlec2p.go b/xds/googledirectpath/googlec2p.go index fab8097e41b7..0f9cb52b7e8f 100644 --- a/xds/googledirectpath/googlec2p.go +++ b/xds/googledirectpath/googlec2p.go @@ -28,7 +28,7 @@ package googledirectpath import ( "encoding/json" "fmt" - "math/rand" + rand "math/rand/v2" "net/url" "sync" "time" diff --git a/xds/internal/balancer/outlierdetection/balancer.go b/xds/internal/balancer/outlierdetection/balancer.go index 4ccff08b51ec..c9d496ce09b9 100644 --- a/xds/internal/balancer/outlierdetection/balancer.go +++ b/xds/internal/balancer/outlierdetection/balancer.go @@ -25,7 +25,7 @@ import ( "encoding/json" "fmt" "math" - "math/rand" + rand "math/rand/v2" "strings" "sync" "sync/atomic" @@ -824,7 +824,7 @@ func (b *outlierDetectionBalancer) successRateAlgorithm() { requiredSuccessRate := mean - stddev*(float64(ejectionCfg.StdevFactor)/1000) if successRate < requiredSuccessRate { channelz.Infof(logger, b.channelzParent, "SuccessRate algorithm detected outlier: %s. Parameters: successRate=%f, mean=%f, stddev=%f, requiredSuccessRate=%f", addrInfo, successRate, mean, stddev, requiredSuccessRate) - if uint32(rand.Int31n(100)) < ejectionCfg.EnforcementPercentage { + if uint32(rand.Int32N(100)) < ejectionCfg.EnforcementPercentage { b.ejectAddress(addrInfo) } } @@ -851,7 +851,7 @@ func (b *outlierDetectionBalancer) failurePercentageAlgorithm() { failurePercentage := (float64(bucket.numFailures) / float64(bucket.numSuccesses+bucket.numFailures)) * 100 if failurePercentage > float64(b.cfg.FailurePercentageEjection.Threshold) { channelz.Infof(logger, b.channelzParent, "FailurePercentage algorithm detected outlier: %s, failurePercentage=%f", addrInfo, failurePercentage) - if uint32(rand.Int31n(100)) < ejectionCfg.EnforcementPercentage { + if uint32(rand.Int32N(100)) < ejectionCfg.EnforcementPercentage { b.ejectAddress(addrInfo) } } diff --git a/xds/internal/balancer/ringhash/e2e/ringhash_balancer_test.go b/xds/internal/balancer/ringhash/e2e/ringhash_balancer_test.go index 6765d827a432..44503b2cd9e8 100644 --- a/xds/internal/balancer/ringhash/e2e/ringhash_balancer_test.go +++ b/xds/internal/balancer/ringhash/e2e/ringhash_balancer_test.go @@ -23,7 +23,7 @@ import ( "errors" "fmt" "math" - "math/rand" + rand "math/rand/v2" "net" "slices" "testing" diff --git a/xds/internal/httpfilter/fault/fault.go b/xds/internal/httpfilter/fault/fault.go index 5a82490598a3..0ffa9c827279 100644 --- a/xds/internal/httpfilter/fault/fault.go +++ b/xds/internal/httpfilter/fault/fault.go @@ -24,7 +24,7 @@ import ( "errors" "fmt" "io" - "math/rand" + rand "math/rand/v2" "strconv" "sync/atomic" "time" @@ -162,7 +162,7 @@ func (i *interceptor) NewStream(ctx context.Context, _ iresolver.RPCInfo, done f } // For overriding in tests -var randIntn = rand.Intn +var randIntn = rand.IntN var newTimer = time.NewTimer func injectDelay(ctx context.Context, delayCfg *cpb.FaultDelay) error { diff --git a/xds/internal/httpfilter/fault/fault_test.go b/xds/internal/httpfilter/fault/fault_test.go index bec9f4c2abbe..f9f6a274be70 100644 --- a/xds/internal/httpfilter/fault/fault_test.go +++ b/xds/internal/httpfilter/fault/fault_test.go @@ -26,7 +26,7 @@ import ( "context" "fmt" "io" - "math/rand" + rand "math/rand/v2" "net" "reflect" "testing" @@ -471,7 +471,7 @@ func (s) TestFaultInjection_Unary(t *testing.T) { for tcNum, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - defer func() { randIntn = rand.Intn; newTimer = time.NewTimer }() + defer func() { randIntn = rand.IntN; newTimer = time.NewTimer }() var intnCalls []int var newTimerCalls []time.Duration randOut := 0 diff --git a/xds/internal/resolver/serviceconfig.go b/xds/internal/resolver/serviceconfig.go index 36776f3debdf..7df75465ac6d 100644 --- a/xds/internal/resolver/serviceconfig.go +++ b/xds/internal/resolver/serviceconfig.go @@ -23,7 +23,7 @@ import ( "encoding/json" "fmt" "math/bits" - "math/rand" + rand "math/rand/v2" "strings" "sync/atomic" "time" diff --git a/xds/internal/resolver/xds_resolver.go b/xds/internal/resolver/xds_resolver.go index de339a7c9b69..1ba6c001d93d 100644 --- a/xds/internal/resolver/xds_resolver.go +++ b/xds/internal/resolver/xds_resolver.go @@ -22,7 +22,7 @@ package resolver import ( "context" "fmt" - "math/rand" + rand "math/rand/v2" "sync/atomic" "google.golang.org/grpc/internal" diff --git a/xds/internal/xdsclient/xdsresource/matcher.go b/xds/internal/xdsclient/xdsresource/matcher.go index 796e9e3008de..798f61884923 100644 --- a/xds/internal/xdsclient/xdsresource/matcher.go +++ b/xds/internal/xdsclient/xdsresource/matcher.go @@ -19,7 +19,7 @@ package xdsresource import ( "fmt" - "math/rand" + rand "math/rand/v2" "strings" "google.golang.org/grpc/internal/grpcutil" @@ -142,11 +142,11 @@ func newFractionMatcher(fraction uint32) *fractionMatcher { return &fractionMatcher{fraction: int64(fraction)} } -// RandInt63n overwrites rand for control in tests. -var RandInt63n = rand.Int63n +// RandInt64n overwrites rand for control in tests. +var RandInt64n = rand.Int64N func (fm *fractionMatcher) match() bool { - t := RandInt63n(1000000) + t := RandInt64n(1000000) return t <= fm.fraction } diff --git a/xds/internal/xdsclient/xdsresource/matcher_test.go b/xds/internal/xdsclient/xdsresource/matcher_test.go index 5d694c741578..de7e3e9be49f 100644 --- a/xds/internal/xdsclient/xdsresource/matcher_test.go +++ b/xds/internal/xdsclient/xdsresource/matcher_test.go @@ -19,7 +19,7 @@ package xdsresource import ( "context" - "math/rand" + rand "math/rand/v2" "testing" "github.com/google/go-cmp/cmp" @@ -119,11 +119,11 @@ func (s) TestFractionMatcherMatch(t *testing.T) { const fraction = 500000 fm := newFractionMatcher(fraction) defer func() { - RandInt63n = rand.Int63n + RandInt64n = rand.Int64N }() // rand > fraction, should return false. - RandInt63n = func(int64) int64 { + RandInt64n = func(int64) int64 { return fraction + 1 } if matched := fm.match(); matched { @@ -131,7 +131,7 @@ func (s) TestFractionMatcherMatch(t *testing.T) { } // rand == fraction, should return true. - RandInt63n = func(int64) int64 { + RandInt64n = func(int64) int64 { return fraction } if matched := fm.match(); !matched { @@ -139,7 +139,7 @@ func (s) TestFractionMatcherMatch(t *testing.T) { } // rand < fraction, should return true. - RandInt63n = func(int64) int64 { + RandInt64n = func(int64) int64 { return fraction - 1 } if matched := fm.match(); !matched {