Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions pgconn/internal/bgreader/bgreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"errors"
"io"
"math/rand"
"math/rand/v2"
"testing"
"time"

Expand Down Expand Up @@ -100,7 +100,7 @@ type numberReader struct {
}

func (nr *numberReader) Read(p []byte) (int, error) {
n := nr.rng.Intn(len(p))
n := nr.rng.IntN(len(p))
for i := range n {
p[i] = nr.v
nr.v++
Expand All @@ -112,16 +112,16 @@ func (nr *numberReader) Read(p []byte) (int, error) {
// TestBGReaderStress stress tests BGReader by reading a lot of bytes in random sizes while randomly starting and
// stopping the background worker from other goroutines.
func TestBGReaderStress(t *testing.T) {
nr := &numberReader{rng: rand.New(rand.NewSource(0))}
nr := &numberReader{rng: rand.New(rand.NewPCG(0, 0))}
bgr := bgreader.New(nr)

bytesRead := 0
var expected uint8
buf := make([]byte, 10_000)
rng := rand.New(rand.NewSource(0))
rng := rand.New(rand.NewPCG(0, 0))

for bytesRead < 1_000_000 {
randomNumber := rng.Intn(100)
randomNumber := rng.IntN(100)
switch {
case randomNumber < 10:
go bgr.Start()
Expand Down
4 changes: 2 additions & 2 deletions pgconn/pgconn_stress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package pgconn_test

import (
"context"
"math/rand"
"math/rand/v2"
"os"
"runtime"
"strconv"
Expand Down Expand Up @@ -37,7 +37,7 @@ func TestConnStress(t *testing.T) {
}

for i := 0; i < actionCount; i++ {
action := actions[rand.Intn(len(actions))]
action := actions[rand.IntN(len(actions))]
err := action.fn(pgConn)
require.Nilf(t, err, "%d: %s", i, action.name)
}
Expand Down
15 changes: 9 additions & 6 deletions pgproto3/chunkreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package pgproto3

import (
"bytes"
"math/rand"
"math/rand/v2"
"testing"
)

Expand Down Expand Up @@ -52,18 +52,21 @@ type randomReader struct {

// Read reads a random number of random bytes.
func (r *randomReader) Read(p []byte) (n int, err error) {
n = r.rnd.Intn(len(p) + 1)
return r.rnd.Read(p[:n])
n = r.rnd.IntN(len(p) + 1)
for i := 0; i < n; i++ {
p[i] = byte(r.rnd.Uint64())
}
return n, nil
}

func TestChunkReaderNextFuzz(t *testing.T) {
rr := &randomReader{rnd: rand.New(rand.NewSource(1))}
rr := &randomReader{rnd: rand.New(rand.NewPCG(1, 0))}
r := newChunkReader(rr, 8192)

randomSizes := rand.New(rand.NewSource(0))
randomSizes := rand.New(rand.NewPCG(0, 0))

for range 100000 {
size := randomSizes.Intn(16384) + 1
size := randomSizes.IntN(16384) + 1
buf, err := r.Next(size)
if err != nil {
t.Fatal(err)
Expand Down
16 changes: 13 additions & 3 deletions pgtype/numeric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"math"
"math/big"
"math/rand"
"math/rand/v2"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -174,14 +174,24 @@ func TestNumericFloat64Valuer(t *testing.T) {
func TestNumericCodecFuzz(t *testing.T) {
skipCockroachDB(t, "server formats numeric text format differently")

r := rand.New(rand.NewSource(0))
r := rand.New(rand.NewPCG(0, 0))
max := &big.Int{}
max.SetString("9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", 10)

tests := make([]pgxtest.ValueRoundTripTest, 0, 2000)
for range 10 {
for j := -50; j < 50; j++ {
num := (&big.Int{}).Rand(r, max)
byteLen := (max.BitLen() + 7) / 8
bytes := make([]byte, byteLen)
for k := 0; k < byteLen; {
val := r.Uint64()
for b := 0; b < 8 && k < byteLen; b++ {
bytes[k] = byte(val >> (b * 8))
k++
}
}
num := new(big.Int).SetBytes(bytes)
num.Mod(num, max)

n := pgtype.Numeric{Int: num, Exp: int32(j), Valid: true}
tests = append(tests, pgxtest.ValueRoundTripTest{n, new(pgtype.Numeric), isExpectedEqNumeric(n)})
Expand Down
2 changes: 1 addition & 1 deletion pgxpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pgxpool
import (
"context"
"errors"
"math/rand"
"math/rand/v2"
"runtime"
"strconv"
"sync"
Expand Down
2 changes: 1 addition & 1 deletion stdlib/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ import (
"fmt"
"io"
"math"
"math/rand"
"math/rand/v2"
"reflect"
"slices"
"strconv"
Expand Down