From 4e45dc79bbdaf7bdbd79239b65001e9a2e127577 Mon Sep 17 00:00:00 2001 From: andig Date: Fri, 21 Aug 2026 16:33:19 +0200 Subject: [PATCH] chore: use math/rand/v2 and Go 1.27 generic rand.N (#33055) --- core/planner/helper_test.go | 2 +- plugin/watchdog_test.go | 2 +- server/modbus/proxy_test.go | 8 ++++---- util/monitor_test.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/planner/helper_test.go b/core/planner/helper_test.go index 8088185bd..92943fe85 100644 --- a/core/planner/helper_test.go +++ b/core/planner/helper_test.go @@ -1,7 +1,7 @@ package planner import ( - "math/rand" + "math/rand/v2" "testing" "time" diff --git a/plugin/watchdog_test.go b/plugin/watchdog_test.go index cec104158..301aecbba 100644 --- a/plugin/watchdog_test.go +++ b/plugin/watchdog_test.go @@ -27,7 +27,7 @@ func TestWatchdogSetterConcurrency(t *testing.T) { return errors.New("race") } - time.Sleep(time.Duration(rand.Int32N(int32(p.timeout)))) + time.Sleep(rand.N(p.timeout)) if !u.CompareAndSwap(1, 0) { return errors.New("race") diff --git a/server/modbus/proxy_test.go b/server/modbus/proxy_test.go index b1427c6e6..50e77c167 100644 --- a/server/modbus/proxy_test.go +++ b/server/modbus/proxy_test.go @@ -2,7 +2,7 @@ package modbus import ( "encoding/binary" - "math/rand" + "math/rand/v2" "net" "sync" "testing" @@ -36,8 +36,8 @@ func TestConcurrentRead(t *testing.T) { require.NoError(t, err) for range 50 { - addr := uint16(rand.Int31n(200) + 1) - qty := uint16(rand.Int31n(32) + 1) + addr := uint16(rand.N(200) + 1) + qty := uint16(rand.N(32) + 1) b, err := conn.ReadInputRegisters(addr, qty) 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)) } }) } diff --git a/util/monitor_test.go b/util/monitor_test.go index 60be90d40..fcc0c3c7c 100644 --- a/util/monitor_test.go +++ b/util/monitor_test.go @@ -2,7 +2,7 @@ package util import ( "context" - "math/rand" + "math/rand/v2" "testing" "time"