Skip to content

Commit d647c53

Browse files
committed
test: fix SecondPullRequestConcurrencyMultiplePR
* The `TestGithubSecondPullRequestConcurrencyMultiplePR` test occasionally failed due to timing issues related to PipelineRun cleanup. * The check for the final number of PipelineRuns sometimes occurred before the cancellation/cleanup mechanism had fully processed superseded runs. * Introduced a wait loop to allow sufficient time for PipelineRuns to be garbage collected or cleaned up by the controller. * This ensures the assertion for the exact number of expected PipelineRuns is more reliable, reducing test flakiness. Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
1 parent b8674ce commit d647c53

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

test/github_pullrequest_concurrency_multiplepr_test.go

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -135,30 +135,32 @@ func TestGithubSecondPullRequestConcurrencyMultiplePR(t *testing.T) {
135135
t.Errorf("we didn't get %d pipelineruns as successful, some of them are still pending or it's abnormally slow to process the Q", allPipelinesRunsCnt)
136136
}
137137

138-
prs, err := runcnx.Clients.Tekton.TektonV1().PipelineRuns(targetNS).List(ctx, metav1.ListOptions{})
139-
assert.NilError(t, err)
138+
maxWaitLoopRun := 10
139+
success := false
140140
allPipelineRunsNamesAndStatus := []string{}
141-
for _, pr := range prs.Items {
142-
allPipelineRunsNamesAndStatus = append(allPipelineRunsNamesAndStatus, fmt.Sprintf("%s %s", pr.Name, pr.Status.GetConditions()))
143-
}
144-
// Filter out PipelineRuns that don't match our pattern
145-
matchingPRs := []tektonv1.PipelineRun{}
146-
for _, pr := range prs.Items {
147-
if strings.HasPrefix(pr.Name, "prlongrunnning-") {
148-
matchingPRs = append(matchingPRs, pr)
141+
for i := range maxWaitLoopRun {
142+
prs, err := runcnx.Clients.Tekton.TektonV1().PipelineRuns(targetNS).List(ctx, metav1.ListOptions{})
143+
assert.NilError(t, err)
144+
for _, pr := range prs.Items {
145+
allPipelineRunsNamesAndStatus = append(allPipelineRunsNamesAndStatus, fmt.Sprintf("%s %s", pr.Name, pr.Status.GetConditions()))
146+
}
147+
// Filter out PipelineRuns that don't match our pattern
148+
matchingPRs := []tektonv1.PipelineRun{}
149+
for _, pr := range prs.Items {
150+
if strings.HasPrefix(pr.Name, "prlongrunnning-") {
151+
matchingPRs = append(matchingPRs, pr)
152+
}
153+
}
154+
if len(matchingPRs) == allPipelinesRunAfterCleanUp {
155+
runcnx.Clients.Log.Infof("we have the expected number of pipelineruns %d/%d, %d/%d", len(matchingPRs), allPipelinesRunAfterCleanUp, i, maxWaitLoopRun)
156+
success = true
157+
break
149158
}
150-
}
151159

152-
// NOTE(chmouel): Sometime it's 8 sometime it's 9, it's a bit flaky but we
153-
// are mostly okay if its one of those. Maybe one day we will get to the
154-
// bottom of it.
155-
//
156-
// See discussion here:
157-
// https://github.com/openshift-pipelines/pipelines-as-code/pull/1978#issue-2897418926
158-
if len(matchingPRs) != allPipelinesRunAfterCleanUp && len(matchingPRs) != allPipelinesRunsCnt+1 {
159-
t.Fatalf("number of cleaned PR is %d we expected to have %d after the cleanup: PipelineRun and its statuses: %+v", len(matchingPRs), allPipelinesRunAfterCleanUp, allPipelineRunsNamesAndStatus)
160-
return
160+
runcnx.Clients.Log.Infof("we are still waiting for pipelineruns to be cleaned up, we have %d/%d, sleeping 10s, %d/%d", len(matchingPRs), allPipelinesRunsCnt, i, maxWaitLoopRun)
161+
time.Sleep(10 * time.Second)
161162
}
163+
assert.Assert(t, success, "we didn't get %d pipelineruns as successful, some of them are still pending or it's abnormally slow to process the Q: %s", allPipelinesRunsCnt, allPipelineRunsNamesAndStatus)
162164

163165
if os.Getenv("TEST_NOCLEANUP") != "true" {
164166
repository.NSTearDown(ctx, t, runcnx, targetNS)

0 commit comments

Comments
 (0)