Skip to content

Commit 5ade485

Browse files
zakiskchmouel
authored andcommitted
fix: Fixed flakiness in TestGitlabCancelInProgressOnPRClose test
in TestGitlabCancelInProgressOnPRClose test repository status was sometime being gotten as Cancelled and sometime it was CancelledStatusRunFinally that's was the reason I think this test was having flakiness. Signed-off-by: Zaki Shaikh <[email protected]>
1 parent f369f4f commit 5ade485

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

test/gitlab_merge_request_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,15 +421,17 @@ func TestGitlabCancelInProgressOnPRClose(t *testing.T) {
421421
})
422422
assert.NilError(t, err)
423423

424-
runcnx.Clients.Log.Infof("Sleeping for 10 seconds to let the pipelinerun to be canceled")
425-
time.Sleep(10 * time.Second)
424+
err = twait.UntilPipelineRunHasReason(ctx, runcnx.Clients, v1.PipelineRunReasonCancelled, waitOpts)
425+
assert.NilError(t, err)
426426

427427
prs, err := runcnx.Clients.Tekton.TektonV1().PipelineRuns(targetNS).List(context.Background(), metav1.ListOptions{})
428428
assert.NilError(t, err)
429429
assert.Equal(t, len(prs.Items), 1, "should have only one pipelinerun, but we have: %d", len(prs.Items))
430430
assert.Equal(t, prs.Items[0].GetStatusCondition().GetCondition(apis.ConditionSucceeded).GetReason(), "Cancelled", "should have been canceled")
431431

432-
repo, err := runcnx.Clients.PipelineAsCode.PipelinesascodeV1alpha1().Repositories(targetNS).Get(ctx, targetNS, metav1.GetOptions{})
432+
// failing on `true` condition because for cancelled PipelineRun we want `false` condition.
433+
waitOpts.FailOnRepoCondition = corev1.ConditionTrue
434+
repo, err := twait.UntilRepositoryUpdated(ctx, runcnx.Clients, waitOpts)
433435
assert.NilError(t, err)
434436

435437
laststatus := repo.Status[len(repo.Status)-1]

test/pkg/wait/wait.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ import (
1616
)
1717

1818
type Opts struct {
19-
RepoName string
20-
Namespace string
21-
MinNumberStatus int
22-
PollTimeout time.Duration
23-
AdminNS string
24-
TargetSHA string
19+
RepoName string
20+
Namespace string
21+
MinNumberStatus int
22+
PollTimeout time.Duration
23+
AdminNS string
24+
TargetSHA string
25+
FailOnRepoCondition corev1.ConditionStatus
2526
}
2627

2728
func UntilMinPRAppeared(ctx context.Context, clients clients.Clients, opts Opts, minNumber int) error {
@@ -58,7 +59,11 @@ func UntilRepositoryUpdated(ctx context.Context, clients clients.Clients, opts O
5859
}
5960
if len(prs.Items) > 0 {
6061
prConditions := prs.Items[0].Status.Conditions
61-
if len(prConditions) != 0 && prConditions[0].Status == corev1.ConditionFalse {
62+
if opts.FailOnRepoCondition == "" {
63+
opts.FailOnRepoCondition = corev1.ConditionFalse
64+
}
65+
66+
if len(prConditions) != 0 && prConditions[0].Status == opts.FailOnRepoCondition {
6267
return true, fmt.Errorf("pipelinerun has failed")
6368
}
6469
}

0 commit comments

Comments
 (0)