Skip to content

Commit

Permalink
Fix flaky test (#24)
Browse files Browse the repository at this point in the history
This PR resolves intermittent test suite execution failures that are caused by
the TestAggregatePromotionPlan test [1].

JIRA Issue [2].

The function signature for generatePromotionPlanTestHelper [3] has been modified to
support a variadic expected promotions parameter.

[1] https://github.com/commercetools/telefonistka/blob/bug/SD-732/internal/pkg/githubapi/promotion_test.go#L174
[2] https://commercetools.atlassian.net/jira/software/c/projects/SD/issues/SD-732?jql=project%20%3D%20%22SD%22%20ORDER%20BY%20created%20DESC
[3] https://github.com/commercetools/telefonistka/blob/bug/SD-732/internal/pkg/githubapi/promotion_test.go#L52
  • Loading branch information
jared-logan-patrick-ct authored Sep 9, 2024
1 parent 4a14b34 commit d4cf1aa
Showing 1 changed file with 45 additions and 22 deletions.
67 changes: 45 additions & 22 deletions internal/pkg/githubapi/promotion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/google/go-github/v62/github"
"github.com/migueleliasweb/go-github-mock/src/mock"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
cfg "github.com/wayfair-incubator/telefonistka/internal/pkg/configuration"
)

Expand Down Expand Up @@ -48,7 +49,7 @@ func generatePromotionPlanMetadataTestHelper(t *testing.T, config *cfg.Config, e
}
}

func generatePromotionPlanTestHelper(t *testing.T, config *cfg.Config, expectedPromotion map[string]PromotionInstance, mockedHTTPClient *http.Client) {
func generatePromotionPlanTestHelper(t *testing.T, config *cfg.Config, mockedHTTPClient *http.Client, expectedPromotions ...map[string]PromotionInstance) {
t.Helper()
ctx := context.Background()
ghClientPair := GhClientPair{v3Client: github.NewClient(mockedHTTPClient)}
Expand All @@ -75,11 +76,17 @@ func generatePromotionPlanTestHelper(t *testing.T, config *cfg.Config, expectedP
t.Fatalf("Failed to generate promotion plan: err=%s", err)
}

if diff := deep.Equal(expectedPromotion, promotionPlan); diff != nil {
for _, l := range diff {
t.Error(l)
expectedPromotionMatched := false
diffs := []string{}
for _, expectedPromotion := range expectedPromotions {
if diff := deep.Equal(expectedPromotion, promotionPlan); diff != nil {
diffs = append(diffs, diff...)
continue
}
expectedPromotionMatched = true
break
}
assert.True(t, expectedPromotionMatched, diffs)
}

func TestGeneratePromotionConditionalPlan(t *testing.T) {
Expand Down Expand Up @@ -161,7 +168,7 @@ func TestGeneratePromotionConditionalPlan(t *testing.T) {
}),
),
)
generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotion)
}

func TestAggregatePromotionPlan(t *testing.T) {
Expand Down Expand Up @@ -197,17 +204,33 @@ func TestAggregatePromotionPlan(t *testing.T) {
},
}

expectedPromotion := map[string]PromotionInstance{
"dev/[^/]*/>prod/eu-east-1/|prod/eu-west-1/": {
ComputedSyncPaths: map[string]string{
"prod/eu-east-1/componentA": "dev/us-east-5/componentA",
"prod/eu-west-1/componentA": "dev/us-east-5/componentA",
expectedPromotions := []map[string]PromotionInstance{
{
"dev/[^/]*/>prod/eu-east-1/|prod/eu-west-1/": {
ComputedSyncPaths: map[string]string{
"prod/eu-east-1/componentA": "dev/us-east-5/componentA",
"prod/eu-west-1/componentA": "dev/us-east-5/componentA",
},
},
"lab/[^/]*/>prod/us-east-1/|prod/us-west-1/": {
ComputedSyncPaths: map[string]string{
"prod/us-east-1/componentA": "lab/us-east-5/componentA",
"prod/us-west-1/componentA": "lab/us-east-5/componentA",
},
},
},
"lab/[^/]*/>prod/us-east-1/|prod/us-west-1/": {
ComputedSyncPaths: map[string]string{
"prod/us-east-1/componentA": "lab/us-east-5/componentA",
"prod/us-west-1/componentA": "lab/us-east-5/componentA",
{
"dev/[^/]*/>prod/eu-east-1/|prod/eu-west-1/": {
ComputedSyncPaths: map[string]string{
"prod/eu-east-1/componentA": "dev/us-east-4/componentA",
"prod/eu-west-1/componentA": "dev/us-east-4/componentA",
},
},
"lab/[^/]*/>prod/us-east-1/|prod/us-west-1/": {
ComputedSyncPaths: map[string]string{
"prod/us-east-1/componentA": "lab/us-east-5/componentA",
"prod/us-west-1/componentA": "lab/us-east-5/componentA",
},
},
},
}
Expand All @@ -233,7 +256,7 @@ func TestAggregatePromotionPlan(t *testing.T) {
),
)

generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotions...)
}

func TestGenerateSourceRegexPromotionPlan(t *testing.T) {
Expand Down Expand Up @@ -283,7 +306,7 @@ func TestGenerateSourceRegexPromotionPlan(t *testing.T) {
}),
),
)
generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotion)
}

func TestGeneratePromotionPlan(t *testing.T) {
Expand Down Expand Up @@ -332,7 +355,7 @@ func TestGeneratePromotionPlan(t *testing.T) {
}),
),
)
generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotion)
}

func TestGeneratePromotionPlanBlockList(t *testing.T) {
Expand Down Expand Up @@ -376,7 +399,7 @@ func TestGeneratePromotionPlanBlockList(t *testing.T) {
},
),
)
generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotion)
}

func TestGeneratePromotionPlanAllowList(t *testing.T) {
Expand Down Expand Up @@ -419,7 +442,7 @@ func TestGeneratePromotionPlanAllowList(t *testing.T) {
},
),
)
generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotion)
}

func TestGeneratePromotionPlanTwoComponents(t *testing.T) {
Expand Down Expand Up @@ -468,7 +491,7 @@ func TestGeneratePromotionPlanTwoComponents(t *testing.T) {
}),
),
)
generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotion)
}

func TestGenerateNestedSourceRegexPromotionPlan(t *testing.T) {
Expand Down Expand Up @@ -515,7 +538,7 @@ func TestGenerateNestedSourceRegexPromotionPlan(t *testing.T) {
}),
),
)
generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotion)
}

func TestGeneratePromotionPlanWithPagination(t *testing.T) {
Expand Down Expand Up @@ -567,7 +590,7 @@ func TestGeneratePromotionPlanWithPagination(t *testing.T) {
}),
),
)
generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotion)
}

// TestGeneratePromotionMetadataWithOutDesc tests the case where the target description is set
Expand Down

0 comments on commit d4cf1aa

Please sign in to comment.