From 67323206c4de3040ceae16dccdc1b56dbe99c341 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Thu, 19 May 2022 10:43:47 -0400 Subject: [PATCH] Alerting: Fix flaky migration test (#48595) (#49190) * Fix flaky migration test (cherry picked from commit 5c32a6b6f60edbc311261e08407cd906832641ee) Co-authored-by: Matthew Jacobson --- .../sqlstore/migrations/ualert/migration_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/services/sqlstore/migrations/ualert/migration_test.go b/pkg/services/sqlstore/migrations/ualert/migration_test.go index 4d9b1340316..0c0a7d13bbb 100644 --- a/pkg/services/sqlstore/migrations/ualert/migration_test.go +++ b/pkg/services/sqlstore/migrations/ualert/migration_test.go @@ -118,7 +118,6 @@ func TestAddDashAlertMigration(t *testing.T) { // TestDashAlertMigration tests the execution of the main DashAlertMigration. func TestDashAlertMigration(t *testing.T) { - t.Skip("Test is flaky") // Run initial migration to have a working DB. x := setupTestDB(t) @@ -444,7 +443,12 @@ func TestDashAlertMigration(t *testing.T) { // Order of nested routes is not guaranteed. cOpt = []cmp.Option{ - cmpopts.SortSlices(func(a, b *ualert.Route) bool { return a.Receiver < b.Receiver }), + cmpopts.SortSlices(func(a, b *ualert.Route) bool { + if a.Receiver != b.Receiver { + return a.Receiver < b.Receiver + } + return a.Matchers[0].Value < b.Matchers[0].Value + }), cmpopts.IgnoreUnexported(ualert.Route{}, labels.Matcher{}), } if !cmp.Equal(tt.expected[orgId].AlertmanagerConfig.Route, amConfig.AlertmanagerConfig.Route, cOpt...) { @@ -481,7 +485,6 @@ var ( ) // createAlertNotification creates a legacy alert notification channel for inserting into the test database. -//nolint func createAlertNotification(t *testing.T, orgId int64, uid string, channelType string, settings string, defaultChannel bool) *models.AlertNotification { t.Helper() settingsJson := simplejson.New() @@ -508,7 +511,6 @@ func createAlertNotification(t *testing.T, orgId int64, uid string, channelType } // createAlert creates a legacy alert rule for inserting into the test database. -//nolint func createAlert(t *testing.T, orgId int64, dashboardId int64, panelsId int64, name string, notifierUids []string) *models.Alert { t.Helper() @@ -665,7 +667,6 @@ func boolPointer(b bool) *bool { } // createAlertNameMatchers creates a temporary alert_name Matchers that will be replaced during runtime with the generated rule_uid. -//nolint func createAlertNameMatchers(alertName string) ualert.Matchers { matcher, _ := labels.NewMatcher(labels.MatchEqual, "alert_name", alertName) return ualert.Matchers(labels.Matchers{matcher})