Skip to content

Commit

Permalink
fixes broken random value generation
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvajagtap committed Jun 12, 2024
1 parent 1bddf2e commit 9ec25ca
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions prepared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ var preparedMessageTests = []struct {
}

func TestPreparedMessage(t *testing.T) {
testRand := rand.New(rand.NewSource(99))
prevMaskRand := maskRand
maskRand = testRand
defer func() { maskRand = prevMaskRand }()

for _, tt := range preparedMessageTests {
var data = []byte("this is a test")
var buf bytes.Buffer
Expand All @@ -43,7 +48,7 @@ func TestPreparedMessage(t *testing.T) {
c.SetCompressionLevel(tt.compressionLevel)

// Seed random number generator for consistent frame mask.
rand.Seed(1234)
testRand.Seed(1234)

if err := c.WriteMessage(tt.messageType, data); err != nil {
t.Fatal(err)
Expand All @@ -59,7 +64,7 @@ func TestPreparedMessage(t *testing.T) {
copy(data, "hello world")

// Seed random number generator for consistent frame mask.
rand.Seed(1234)
testRand.Seed(1234)

buf.Reset()
if err := c.WritePreparedMessage(pm); err != nil {
Expand Down

0 comments on commit 9ec25ca

Please sign in to comment.