From 4468aac4ee5dc051b8456a3537a9628b221bfcb9 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Tue, 11 Oct 2022 08:43:51 -0400 Subject: [PATCH] [v9.2.x] Alerting: Mark all tests that interact with the database as integration tests (#56603) Previously, two tests were not explicitly marked as integration tests and so were not run against all 3 supported databases in the CI environment. (cherry picked from commit 7312a2dab0c9fad6faee29bb6133a0485df11b4b) Co-authored-by: Joe Blubaugh --- pkg/services/ngalert/models/testing.go | 14 +++++++------- pkg/services/ngalert/ngalert_test.go | 2 +- pkg/services/ngalert/store/alert_rule_test.go | 5 ++--- .../ngalert/store/provisioning_store_test.go | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pkg/services/ngalert/models/testing.go b/pkg/services/ngalert/models/testing.go index a8c3c57b76f..002aec62903 100644 --- a/pkg/services/ngalert/models/testing.go +++ b/pkg/services/ngalert/models/testing.go @@ -54,25 +54,25 @@ func AlertRuleGen(mutators ...AlertRuleMutator) func() *AlertRule { if rand.Int63()%2 == 0 { d := util.GenerateShortUID() dashUID = &d - p := rand.Int63() + p := rand.Int63n(1 << 30) panelID = &p } rule := &AlertRule{ - ID: rand.Int63(), - OrgID: rand.Int63(), + ID: rand.Int63n(1 << 30), + OrgID: rand.Int63n(1 << 30), Title: "TEST-ALERT-" + util.GenerateShortUID(), Condition: "A", Data: []AlertQuery{GenerateAlertQuery()}, Updated: time.Now().Add(-time.Duration(rand.Intn(100) + 1)), IntervalSeconds: rand.Int63n(60) + 1, - Version: rand.Int63(), + Version: rand.Int63n(1 << 30), UID: util.GenerateShortUID(), NamespaceUID: util.GenerateShortUID(), DashboardUID: dashUID, PanelID: panelID, RuleGroup: "TEST-GROUP-" + util.GenerateShortUID(), - RuleGroupIndex: rand.Int(), + RuleGroupIndex: rand.Intn(1 << 30), NoDataState: randNoDataState(), ExecErrState: randErrState(), For: forInterval, @@ -96,7 +96,7 @@ func WithUniqueID() AlertRuleMutator { usedID := make(map[int64]struct{}) return func(rule *AlertRule) { for { - id := rand.Int63() + id := rand.Int63n(1 << 30) if _, ok := usedID[id]; !ok { usedID[id] = struct{}{} rule.ID = id @@ -116,7 +116,7 @@ func WithUniqueGroupIndex() AlertRuleMutator { usedIdx := make(map[int]struct{}) return func(rule *AlertRule) { for { - idx := rand.Int() + idx := rand.Intn(1 << 30) if _, ok := usedIdx[idx]; !ok { usedIdx[idx] = struct{}{} rule.RuleGroupIndex = idx diff --git a/pkg/services/ngalert/ngalert_test.go b/pkg/services/ngalert/ngalert_test.go index a1911eb25b4..32daf5f777f 100644 --- a/pkg/services/ngalert/ngalert_test.go +++ b/pkg/services/ngalert/ngalert_test.go @@ -20,7 +20,7 @@ import ( ) func Test_subscribeToFolderChanges(t *testing.T) { - orgID := rand.Int63() + orgID := rand.Int63n(30) folder := &models2.Folder{ Id: 0, Uid: util.GenerateShortUID(), diff --git a/pkg/services/ngalert/store/alert_rule_test.go b/pkg/services/ngalert/store/alert_rule_test.go index 0232c28d61b..41a87f40bfc 100644 --- a/pkg/services/ngalert/store/alert_rule_test.go +++ b/pkg/services/ngalert/store/alert_rule_test.go @@ -17,7 +17,7 @@ import ( "github.com/grafana/grafana/pkg/util" ) -func TestUpdateAlertRules(t *testing.T) { +func TestIntegrationUpdateAlertRules(t *testing.T) { sqlStore := sqlstore.InitTestDB(t) store := DBstore{ SQLStore: sqlStore, @@ -26,7 +26,6 @@ func TestUpdateAlertRules(t *testing.T) { }, } createRule := func(t *testing.T) *models.AlertRule { - t.Helper() rule := models.AlertRuleGen(withIntervalMatching(store.Cfg.BaseInterval))() err := sqlStore.WithDbSession(context.Background(), func(sess *sqlstore.DBSession) error { _, err := sess.Table(models.AlertRule{}).InsertOne(rule) @@ -94,7 +93,7 @@ func withIntervalMatching(baseInterval time.Duration) func(*models.AlertRule) { } } -func Test_getFilterByOrgsString(t *testing.T) { +func TestIntegration_getFilterByOrgsString(t *testing.T) { testCases := []struct { testName string orgs map[int64]struct{} diff --git a/pkg/services/ngalert/store/provisioning_store_test.go b/pkg/services/ngalert/store/provisioning_store_test.go index f8c8cac2cc6..356079ae022 100644 --- a/pkg/services/ngalert/store/provisioning_store_test.go +++ b/pkg/services/ngalert/store/provisioning_store_test.go @@ -14,7 +14,7 @@ import ( const testAlertingIntervalSeconds = 10 -func TestProvisioningStore(t *testing.T) { +func TestIntegrationProvisioningStore(t *testing.T) { store := createProvisioningStoreSut(tests.SetupTestEnv(t, testAlertingIntervalSeconds)) t.Run("Default provenance of a known type is None", func(t *testing.T) {