stop using math/rand.Seed and Read in tests, bump go.mod version to 1.20 (#3936)

This commit is contained in:
Marten Seemann 2023-07-01 11:29:41 -07:00 committed by GitHub
parent 3d89e545d3
commit 0662afba63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 45 additions and 43 deletions

View file

@ -4,9 +4,10 @@ import (
"bytes"
"fmt"
"math"
"math/rand"
"time"
"golang.org/x/exp/rand"
"github.com/quic-go/quic-go/internal/protocol"
. "github.com/onsi/ginkgo/v2"
@ -1408,7 +1409,7 @@ var _ = Describe("frame sorter", func() {
BeforeEach(func() {
seed := time.Now().UnixNano()
fmt.Fprintf(GinkgoWriter, "Seed: %d\n", seed)
rand.Seed(seed)
rand.Seed(uint64(seed))
callbacks = nil
dataLen = 25

View file

@ -2,9 +2,10 @@ package main
import (
"log"
"math/rand"
"time"
"golang.org/x/exp/rand"
"github.com/quic-go/quic-go"
"github.com/quic-go/quic-go/fuzzing/internal/helper"
"github.com/quic-go/quic-go/internal/protocol"

View file

@ -2,7 +2,8 @@ package main
import (
"log"
"math/rand"
"golang.org/x/exp/rand"
"github.com/quic-go/quic-go/fuzzing/header"
"github.com/quic-go/quic-go/fuzzing/internal/helper"

View file

@ -3,10 +3,11 @@ package main
import (
"log"
"math"
"math/rand"
"net"
"time"
"golang.org/x/exp/rand"
"github.com/quic-go/quic-go/fuzzing/internal/helper"
"github.com/quic-go/quic-go/fuzzing/transportparameters"
"github.com/quic-go/quic-go/internal/protocol"

2
go.mod
View file

@ -1,6 +1,6 @@
module github.com/quic-go/quic-go
go 1.19
go 1.20
require (
github.com/francoispqt/gojay v1.2.13

View file

@ -6,11 +6,12 @@ import (
"fmt"
"io"
"math"
mrand "math/rand"
"net"
"sync/atomic"
"time"
"golang.org/x/exp/rand"
"github.com/quic-go/quic-go"
quicproxy "github.com/quic-go/quic-go/integrationtests/tools/proxy"
"github.com/quic-go/quic-go/internal/protocol"
@ -110,17 +111,17 @@ var _ = Describe("MITM test", func() {
Type: hdr.Type,
Version: hdr.Version,
},
PacketNumber: protocol.PacketNumber(mrand.Int31n(math.MaxInt32 / 4)),
PacketNumberLen: protocol.PacketNumberLen(mrand.Int31n(4) + 1),
PacketNumber: protocol.PacketNumber(rand.Int31n(math.MaxInt32 / 4)),
PacketNumberLen: protocol.PacketNumberLen(rand.Int31n(4) + 1),
}
for i := 0; i < numPackets; i++ {
payloadLen := mrand.Int31n(100)
replyHdr.Length = protocol.ByteCount(mrand.Int31n(payloadLen + 1))
payloadLen := rand.Int31n(100)
replyHdr.Length = protocol.ByteCount(rand.Int31n(payloadLen + 1))
b, err := replyHdr.Append(nil, hdr.Version)
Expect(err).ToNot(HaveOccurred())
r := make([]byte, payloadLen)
mrand.Read(r)
rand.Read(r)
b = append(b, r...)
if _, err := conn.WriteTo(b, remoteAddr); err != nil {
return
@ -135,11 +136,11 @@ var _ = Describe("MITM test", func() {
Expect(err).To(MatchError(wire.ErrInvalidReservedBits))
}
for i := 0; i < numPackets; i++ {
b, err := wire.AppendShortHeader(nil, connID, pn, pnLen, protocol.KeyPhaseBit(mrand.Intn(2)))
b, err := wire.AppendShortHeader(nil, connID, pn, pnLen, protocol.KeyPhaseBit(rand.Intn(2)))
Expect(err).ToNot(HaveOccurred())
payloadLen := mrand.Int31n(100)
payloadLen := rand.Int31n(100)
r := make([]byte, payloadLen)
mrand.Read(r)
rand.Read(r)
b = append(b, r...)
if _, err := conn.WriteTo(b, remoteAddr); err != nil {
return
@ -272,9 +273,9 @@ var _ = Describe("MITM test", func() {
defer GinkgoRecover()
if dir == quicproxy.DirectionIncoming {
atomic.AddInt32(&numPackets, 1)
if mrand.Intn(interval) == 0 {
pos := mrand.Intn(len(raw))
raw[pos] = byte(mrand.Intn(256))
if rand.Intn(interval) == 0 {
pos := rand.Intn(len(raw))
raw[pos] = byte(rand.Intn(256))
_, err := clientUDPConn.WriteTo(raw, serverUDPConn.LocalAddr())
Expect(err).ToNot(HaveOccurred())
atomic.AddInt32(&numCorrupted, 1)
@ -292,9 +293,9 @@ var _ = Describe("MITM test", func() {
defer GinkgoRecover()
if dir == quicproxy.DirectionOutgoing {
atomic.AddInt32(&numPackets, 1)
if mrand.Intn(interval) == 0 {
pos := mrand.Intn(len(raw))
raw[pos] = byte(mrand.Intn(256))
if rand.Intn(interval) == 0 {
pos := rand.Intn(len(raw))
raw[pos] = byte(rand.Intn(256))
_, err := serverUDPConn.WriteTo(raw, clientUDPConn.LocalAddr())
Expect(err).ToNot(HaveOccurred())
atomic.AddInt32(&numCorrupted, 1)

View file

@ -8,7 +8,6 @@ import (
"flag"
"fmt"
"log"
mrand "math/rand"
"os"
"runtime/pprof"
"strconv"
@ -139,8 +138,6 @@ func init() {
}
var _ = BeforeSuite(func() {
mrand.Seed(GinkgoRandomSeed())
if enableQlog {
qlogTracer = tools.NewQlogger(GinkgoWriter)
}

View file

@ -2,8 +2,8 @@ package self_test
import (
"context"
"crypto/rand"
"fmt"
"math/rand"
"net"
"sync/atomic"
"time"

View file

@ -1,7 +1,6 @@
package ackhandler
import (
"math/rand"
"testing"
"github.com/golang/mock/gomock"
@ -16,10 +15,6 @@ func TestCrypto(t *testing.T) {
var mockCtrl *gomock.Controller
var _ = BeforeSuite(func() {
rand.Seed(GinkgoRandomSeed())
})
var _ = BeforeEach(func() {
mockCtrl = gomock.NewController(GinkgoT())
})

View file

@ -1,8 +1,8 @@
package handshake
import (
"crypto/rand"
"fmt"
"math/rand"
"github.com/quic-go/quic-go/internal/protocol"

View file

@ -4,10 +4,11 @@ import (
"bytes"
"fmt"
"math"
"math/rand"
"net"
"time"
"golang.org/x/exp/rand"
"github.com/quic-go/quic-go/internal/protocol"
"github.com/quic-go/quic-go/internal/qerr"
"github.com/quic-go/quic-go/quicvarint"
@ -31,7 +32,7 @@ var _ = Describe("Transport Parameters", func() {
}
BeforeEach(func() {
rand.Seed(GinkgoRandomSeed())
rand.Seed(uint64(GinkgoRandomSeed()))
})
appendInitialSourceConnectionID := func(b []byte) []byte {

View file

@ -2,7 +2,6 @@ package wire
import (
"encoding/binary"
mrand "math/rand"
"golang.org/x/exp/rand"
@ -15,7 +14,7 @@ import (
var _ = Describe("Version Negotiation Packets", func() {
randConnID := func(l int) protocol.ArbitraryLenConnectionID {
b := make(protocol.ArbitraryLenConnectionID, l)
_, err := mrand.Read(b)
_, err := rand.Read(b)
Expect(err).ToNot(HaveOccurred())
return b
}

View file

@ -3,10 +3,11 @@ package quic
import (
"bytes"
"fmt"
"math/rand"
"net"
"time"
"golang.org/x/exp/rand"
"github.com/quic-go/quic-go/internal/ackhandler"
"github.com/quic-go/quic-go/internal/handshake"
"github.com/quic-go/quic-go/internal/mocks"
@ -84,7 +85,7 @@ var _ = Describe("Packet packer", func() {
}
BeforeEach(func() {
rand.Seed(GinkgoRandomSeed())
rand.Seed(uint64(GinkgoRandomSeed()))
retransmissionQueue = newRetransmissionQueue()
mockSender := NewMockStreamSender(mockCtrl)
mockSender.EXPECT().onHasStreamData(gomock.Any()).AnyTimes()

View file

@ -8,6 +8,8 @@ import (
"runtime"
"time"
"golang.org/x/exp/rand"
"github.com/golang/mock/gomock"
"github.com/quic-go/quic-go/internal/ackhandler"
"github.com/quic-go/quic-go/internal/mocks"
@ -1169,7 +1171,7 @@ var _ = Describe("Send Stream", func() {
mockFC.EXPECT().AddBytesSent(gomock.Any()).AnyTimes()
data := make([]byte, dataLen)
_, err := mrand.Read(data)
_, err := rand.Read(data)
Expect(err).ToNot(HaveOccurred())
done := make(chan struct{})
go func() {

View file

@ -3,9 +3,10 @@ package quic
import (
"context"
"errors"
"math/rand"
"time"
"golang.org/x/exp/rand"
"github.com/quic-go/quic-go/internal/protocol"
"github.com/quic-go/quic-go/internal/wire"
@ -274,7 +275,7 @@ var _ = Describe("Streams Map (incoming)", func() {
BeforeEach(func() { maxNumStreams = num })
It("opens and accepts streams", func() {
rand.Seed(GinkgoRandomSeed())
rand.Seed(uint64(GinkgoRandomSeed()))
ids := make([]protocol.StreamNum, num)
for i := 0; i < num; i++ {
ids[i] = protocol.StreamNum(i + 1)

View file

@ -4,11 +4,12 @@ import (
"context"
"errors"
"fmt"
"math/rand"
"sort"
"sync"
"time"
"golang.org/x/exp/rand"
"github.com/quic-go/quic-go/internal/protocol"
"github.com/quic-go/quic-go/internal/wire"
@ -410,7 +411,7 @@ var _ = Describe("Streams Map (outgoing)", func() {
Context("randomized tests", func() {
It("opens streams", func() {
rand.Seed(GinkgoRandomSeed())
rand.Seed(uint64(GinkgoRandomSeed()))
const n = 100
fmt.Fprintf(GinkgoWriter, "Opening %d streams concurrently.\n", n)
@ -461,7 +462,7 @@ var _ = Describe("Streams Map (outgoing)", func() {
})
It("opens streams, when some of them are getting canceled", func() {
rand.Seed(GinkgoRandomSeed())
rand.Seed(uint64(GinkgoRandomSeed()))
const n = 100
fmt.Fprintf(GinkgoWriter, "Opening %d streams concurrently.\n", n)