Alerting: Fix flaky tests (#104017)
Alerting: fix flaky tests Some test conditions introduced in #103403 are flaky because they rely on random behavior of the generator. Sometimes rules are generated with an updated by (which warrants the lookup of the users). This makes it so those tests which are checking the user lookup always have rules with updated by.
This commit is contained in:
@@ -666,8 +666,10 @@ func TestRouteGetRulesConfig(t *testing.T) {
|
||||
group2Key := models.GenerateGroupKey(orgID)
|
||||
group2Key.NamespaceUID = folder2.UID
|
||||
|
||||
group1 := gen.With(gen.WithGroupKey(group1Key)).GenerateManyRef(2, 6)
|
||||
group2 := gen.With(gen.WithGroupKey(group2Key)).GenerateManyRef(2, 6)
|
||||
ruleUpdatedBy := util.Pointer(models.UserUID(util.GenerateShortUID()))
|
||||
|
||||
group1 := gen.With(gen.WithGroupKey(group1Key), gen.WithUpdatedBy(ruleUpdatedBy)).GenerateManyRef(2, 6)
|
||||
group2 := gen.With(gen.WithGroupKey(group2Key), gen.WithUpdatedBy(ruleUpdatedBy)).GenerateManyRef(2, 6)
|
||||
ruleStore.PutRule(context.Background(), append(group1, group2...)...)
|
||||
|
||||
t.Run("and do not return group if user does not have access to one of rules", func(t *testing.T) {
|
||||
@@ -704,7 +706,9 @@ func TestRouteGetRulesConfig(t *testing.T) {
|
||||
groupKey := models.GenerateGroupKey(orgID)
|
||||
groupKey.NamespaceUID = folder.UID
|
||||
|
||||
expectedRules := gen.With(gen.WithGroupKey(groupKey), gen.WithUniqueGroupIndex()).GenerateManyRef(5, 10)
|
||||
ruleUpdatedBy := util.Pointer(models.UserUID(util.GenerateShortUID()))
|
||||
|
||||
expectedRules := gen.With(gen.WithGroupKey(groupKey), gen.WithUniqueGroupIndex(), gen.WithUpdatedBy(ruleUpdatedBy)).GenerateManyRef(5, 10)
|
||||
ruleStore.PutRule(context.Background(), expectedRules...)
|
||||
|
||||
perms := createPermissionsForRules(expectedRules, orgID)
|
||||
@@ -753,7 +757,9 @@ func TestRouteGetRulesGroupConfig(t *testing.T) {
|
||||
groupKey := models.GenerateGroupKey(orgID)
|
||||
groupKey.NamespaceUID = folder.UID
|
||||
|
||||
expectedRules := gen.With(gen.WithGroupKey(groupKey), gen.WithUniqueGroupIndex()).GenerateManyRef(5, 10)
|
||||
ruleUpdatedBy := util.Pointer(models.UserUID(util.GenerateShortUID()))
|
||||
|
||||
expectedRules := gen.With(gen.WithGroupKey(groupKey), gen.WithUniqueGroupIndex(), gen.WithUpdatedBy(ruleUpdatedBy)).GenerateManyRef(5, 10)
|
||||
ruleStore.PutRule(context.Background(), expectedRules...)
|
||||
|
||||
perms := createPermissionsForRules(expectedRules, orgID)
|
||||
|
||||
Reference in New Issue
Block a user