Skip to content

Commit

Permalink
No usage of math/rand (#16264)
Browse files Browse the repository at this point in the history
Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink authored Jun 27, 2024
1 parent ddd1630 commit 9c9cad8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ run:
timeout: 10m

linters-settings:
depguard:
rules:
use_modern_packages:
list-mode: lax
deny:
- pkg: "math/rand$"
desc: Please use math/rand/v2
errcheck:
exclude: ./misc/errcheck_excludes.txt
goimports:
Expand All @@ -17,6 +24,7 @@ linters:
disable-all: true
enable:
# Defaults
- depguard
- errcheck
- govet
- ineffassign
Expand Down
4 changes: 2 additions & 2 deletions go/test/endtoend/backup/vtctlbackup/backup_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"context"
"encoding/json"
"fmt"
"math/rand"
"math/rand/v2"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -1313,7 +1313,7 @@ func TestReplicaRestoreToPos(t *testing.T, replicaIndex int, restoreToPos replic
require.False(t, restoreToPos.IsZero())
restoreToPosArg := replication.EncodePosition(restoreToPos)
assert.Contains(t, restoreToPosArg, "MySQL56/")
if rand.Intn(2) == 0 {
if rand.IntN(2) == 0 {
// Verify that restore works whether or not the MySQL56/ prefix is present.
restoreToPosArg = strings.Replace(restoreToPosArg, "MySQL56/", "", 1)
assert.NotContains(t, restoreToPosArg, "MySQL56/")
Expand Down
5 changes: 3 additions & 2 deletions go/test/endtoend/vreplication/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package vreplication

import (
"context"
crand "crypto/rand"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"math/rand"
"math/rand/v2"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -752,7 +753,7 @@ func verifyCopyStateIsOptimized(t *testing.T, tablet *cluster.VttabletProcess) {
// be used to generate and insert test data.
func randHex(n int) (string, error) {
bytes := make([]byte, n)
if _, err := rand.Read(bytes); err != nil {
if _, err := crand.Read(bytes); err != nil {
return "", err
}
return hex.EncodeToString(bytes), nil
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtctl/workflow/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"
"math"
"math/rand"
"math/rand/v2"
"os"
"os/exec"
"sync"
Expand Down Expand Up @@ -103,7 +103,7 @@ func testConcurrentKeyspaceRoutingRulesUpdates(t *testing.T, ctx context.Context
func update(t *testing.T, ts *topo.Server, id int) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
s := fmt.Sprintf("%d_%d", id, rand.Intn(math.MaxInt))
s := fmt.Sprintf("%d_%d", id, rand.IntN(math.MaxInt))
routes := make(map[string]string)
for _, tabletType := range tabletTypeSuffixes {
from := fmt.Sprintf("from%s%s", s, tabletType)
Expand Down

0 comments on commit 9c9cad8

Please sign in to comment.