From f2b40dbe9afb96f9a50b00edd9e77f609bdb3258 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 23 Jan 2023 19:25:08 -0800 Subject: [PATCH] app/vmalert: use consistent randomizer in tests Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3683 --- app/vmalert/manager_test.go | 7 ++++--- app/vmalert/notifier/config_watcher_test.go | 7 ++++--- app/vmalert/remotewrite/remotewrite_test.go | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/vmalert/manager_test.go b/app/vmalert/manager_test.go index b56dfb67c..ba1f23dde 100644 --- a/app/vmalert/manager_test.go +++ b/app/vmalert/manager_test.go @@ -64,17 +64,18 @@ func TestManagerUpdateConcurrent(t *testing.T) { wg := sync.WaitGroup{} wg.Add(workers) for i := 0; i < workers; i++ { - go func() { + go func(n int) { defer wg.Done() + r := rand.New(rand.NewSource(int64(n))) for i := 0; i < iterations; i++ { - rnd := rand.Intn(len(paths)) + rnd := r.Intn(len(paths)) cfg, err := config.Parse([]string{paths[rnd]}, notifier.ValidateTemplates, true) if err != nil { // update can fail and this is expected continue } _ = m.update(context.Background(), cfg, false) } - }() + }(i) } wg.Wait() } diff --git a/app/vmalert/notifier/config_watcher_test.go b/app/vmalert/notifier/config_watcher_test.go index 61550a626..b51cd3bfa 100644 --- a/app/vmalert/notifier/config_watcher_test.go +++ b/app/vmalert/notifier/config_watcher_test.go @@ -162,14 +162,15 @@ consul_sd_configs: wg := sync.WaitGroup{} wg.Add(workers) for i := 0; i < workers; i++ { - go func() { + go func(n int) { defer wg.Done() + r := rand.New(rand.NewSource(int64(n))) for i := 0; i < iterations; i++ { - rnd := rand.Intn(len(paths)) + rnd := r.Intn(len(paths)) _ = cw.reload(paths[rnd]) // update can fail and this is expected _ = cw.notifiers() } - }() + }(i) } wg.Wait() } diff --git a/app/vmalert/remotewrite/remotewrite_test.go b/app/vmalert/remotewrite/remotewrite_test.go index 668c422df..4ca9812a5 100644 --- a/app/vmalert/remotewrite/remotewrite_test.go +++ b/app/vmalert/remotewrite/remotewrite_test.go @@ -27,12 +27,13 @@ func TestClient_Push(t *testing.T) { if err != nil { t.Fatalf("failed to create client: %s", err) } + r := rand.New(rand.NewSource(1)) const rowsN = 1e4 var sent int for i := 0; i < rowsN; i++ { s := prompbmarshal.TimeSeries{ Samples: []prompbmarshal.Sample{{ - Value: rand.Float64(), + Value: r.Float64(), Timestamp: time.Now().Unix(), }}, }