diff --git a/app/vmalert/rule/group_test.go b/app/vmalert/rule/group_test.go index d1777b6c54..b7560c1aeb 100644 --- a/app/vmalert/rule/group_test.go +++ b/app/vmalert/rule/group_test.go @@ -217,7 +217,6 @@ func TestGroupStart(t *testing.T) { const evalInterval = time.Millisecond g := NewGroup(groups[0], fs, evalInterval, map[string]string{"cluster": "east-1"}) - g.Concurrency = 2 const inst1, inst2, job = "foo", "bar", "baz" m1 := metricWithLabels(t, "instance", inst1, "job", job) @@ -262,8 +261,25 @@ func TestGroupStart(t *testing.T) { close(finished) }() - // wait for multiple evals - time.Sleep(20 * evalInterval) + waitForIterations := func(n int, interval time.Duration) { + t.Helper() + + var cur uint64 + prev := g.metrics.iterationTotal.Get() + for i := 0; ; i++ { + if i > 40 { + t.Fatalf("group wasn't able to perform %d evaluations during %d eval intervals", n, i) + } + cur = g.metrics.iterationTotal.Get() + if int(cur-prev) >= n { + return + } + time.Sleep(interval) + } + } + + // wait for multiple evaluation iterations + waitForIterations(4, evalInterval) gotAlerts := fn.GetAlerts() expectedAlerts := []notifier.Alert{*alert1, *alert2} @@ -280,8 +296,8 @@ func TestGroupStart(t *testing.T) { // and set only one datapoint for response fs.Add(m1) - // wait for multiple evals - time.Sleep(20 * evalInterval) + // wait for multiple evaluation iterations + waitForIterations(4, evalInterval) gotAlerts = fn.GetAlerts() alert2.State = notifier.StateInactive