chore: use math/rand/v2 and Go 1.27 generic rand.N (#33055)
This commit is contained in:
parent
9600fc5b9f
commit
4e45dc79bb
4 changed files with 7 additions and 7 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
package planner
|
package planner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ func TestWatchdogSetterConcurrency(t *testing.T) {
|
||||||
return errors.New("race")
|
return errors.New("race")
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(time.Duration(rand.Int32N(int32(p.timeout))))
|
time.Sleep(rand.N(p.timeout))
|
||||||
|
|
||||||
if !u.CompareAndSwap(1, 0) {
|
if !u.CompareAndSwap(1, 0) {
|
||||||
return errors.New("race")
|
return errors.New("race")
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package modbus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -36,8 +36,8 @@ func TestConcurrentRead(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
for range 50 {
|
for range 50 {
|
||||||
addr := uint16(rand.Int31n(200) + 1)
|
addr := uint16(rand.N(200) + 1)
|
||||||
qty := uint16(rand.Int31n(32) + 1)
|
qty := uint16(rand.N(32) + 1)
|
||||||
|
|
||||||
b, err := conn.ReadInputRegisters(addr, qty)
|
b, err := conn.ReadInputRegisters(addr, qty)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -48,7 +48,7 @@ func TestConcurrentRead(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(time.Duration(rand.Int31n(1000)) * time.Microsecond)
|
time.Sleep(rand.N(time.Millisecond))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue