mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-16 17:21:04 +01:00
app/vmalert: make TestGroupStart
more reliable (#6130)
There was a sleep statement in the test, waiting for Group to perform a couple of evaluation. But looks like it worked unreliable for some CI tests like the one below https://github.com/VictoriaMetrics/VictoriaMetrics/actions/runs/8718213844/job/23915007958?pr=6115 This commit changes the sleep statement on a function that waits for a specific number of evaluations. It should make this test faster in general case, and more reliable for slow environemnts.
This commit is contained in:
parent
f3967737b0
commit
95b0f82c9b
@ -217,7 +217,6 @@ func TestGroupStart(t *testing.T) {
|
|||||||
|
|
||||||
const evalInterval = time.Millisecond
|
const evalInterval = time.Millisecond
|
||||||
g := NewGroup(groups[0], fs, evalInterval, map[string]string{"cluster": "east-1"})
|
g := NewGroup(groups[0], fs, evalInterval, map[string]string{"cluster": "east-1"})
|
||||||
g.Concurrency = 2
|
|
||||||
|
|
||||||
const inst1, inst2, job = "foo", "bar", "baz"
|
const inst1, inst2, job = "foo", "bar", "baz"
|
||||||
m1 := metricWithLabels(t, "instance", inst1, "job", job)
|
m1 := metricWithLabels(t, "instance", inst1, "job", job)
|
||||||
@ -262,8 +261,25 @@ func TestGroupStart(t *testing.T) {
|
|||||||
close(finished)
|
close(finished)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// wait for multiple evals
|
waitForIterations := func(n int, interval time.Duration) {
|
||||||
time.Sleep(20 * evalInterval)
|
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()
|
gotAlerts := fn.GetAlerts()
|
||||||
expectedAlerts := []notifier.Alert{*alert1, *alert2}
|
expectedAlerts := []notifier.Alert{*alert1, *alert2}
|
||||||
@ -280,8 +296,8 @@ func TestGroupStart(t *testing.T) {
|
|||||||
// and set only one datapoint for response
|
// and set only one datapoint for response
|
||||||
fs.Add(m1)
|
fs.Add(m1)
|
||||||
|
|
||||||
// wait for multiple evals
|
// wait for multiple evaluation iterations
|
||||||
time.Sleep(20 * evalInterval)
|
waitForIterations(4, evalInterval)
|
||||||
|
|
||||||
gotAlerts = fn.GetAlerts()
|
gotAlerts = fn.GetAlerts()
|
||||||
alert2.State = notifier.StateInactive
|
alert2.State = notifier.StateInactive
|
||||||
|
Loading…
Reference in New Issue
Block a user