diff --git a/cmd/promtool/unittest.go b/cmd/promtool/unittest.go index 682ebc66b..6069ec3f9 100644 --- a/cmd/promtool/unittest.go +++ b/cmd/promtool/unittest.go @@ -228,6 +228,7 @@ func (tg *testGroup) test(evalInterval time.Duration, groupOrderMap map[string]i var errs []error for ts := mint; ts.Before(maxt) || ts.Equal(maxt); ts = ts.Add(evalInterval) { // Collects the alerts asked for unit testing. + var evalErrs []error suite.WithSamplesTill(ts, func(err error) { if err != nil { errs = append(errs, err) @@ -237,13 +238,16 @@ func (tg *testGroup) test(evalInterval time.Duration, groupOrderMap map[string]i g.Eval(suite.Context(), ts) for _, r := range g.Rules() { if r.LastError() != nil { - errs = append(errs, errors.Errorf(" rule: %s, time: %s, err: %v", + evalErrs = append(evalErrs, errors.Errorf(" rule: %s, time: %s, err: %v", r.Name(), ts.Sub(time.Unix(0, 0).UTC()), r.LastError())) } } } }) - if len(errs) > 0 { + errs = append(errs, evalErrs...) + // Only end testing at this point if errors occurred evaluating above, + // rather than any test failures already collected in errs. + if len(evalErrs) > 0 { return errs }