Skip to content

Commit 11e7bc2

Browse files
chmoueltheakshaypant
authored andcommitted
fix: TestGHEPullRequestGitopsCommentCancel race
The E2E test TestGithubGHEPullRequestGitopsCommentCancel in test/github_pullrequest_retest_test.go:64 fails intermittently because it uses the wrong wait strategy after issuing /cancel. The test uses UntilRepositoryUpdated with MinNumberStatus: 3, which passes immediately when there are already ≥3 repo statuses — before the cancel has taken effect. The last status is then ConditionTrue (succeeded) instead of the expected ConditionFalse (cancelled) Reuse the same robust pattern that we already do in test/github_push_retest_test.go:194-211, it does this: 1. Waits for the PipelineRun to have Cancelled reason via UntilPipelineRunHasReason 2. Then waits for the Repository status to have Cancelled reason via UntilRepositoryHasStatusReason 3. Falls back to checking controller logs if the cancel didn't propagate
1 parent 0faad24 commit 11e7bc2

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

test/github_pullrequest_retest_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import (
77
"fmt"
88
"strings"
99
"testing"
10+
"time"
1011

1112
"github.com/google/go-github/v84/github"
1213
"github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/keys"
1314
tgithub "github.com/openshift-pipelines/pipelines-as-code/test/pkg/github"
1415
twait "github.com/openshift-pipelines/pipelines-as-code/test/pkg/wait"
16+
tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
1517
"gotest.tools/v3/assert"
1618
corev1 "k8s.io/api/core/v1"
1719
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -98,21 +100,21 @@ func TestGithubGHEPullRequestGitopsCommentCancel(t *testing.T) {
98100
&github.IssueComment{Body: github.Ptr("/cancel pr-gitops-comment")})
99101
assert.NilError(t, err)
100102

101-
waitOpts = twait.Opts{
103+
cancelWaitOpts := twait.Opts{
102104
RepoName: g.TargetNamespace,
103105
Namespace: g.TargetNamespace,
104-
MinNumberStatus: 3,
105-
PollTimeout: twait.DefaultTimeout,
106+
MinNumberStatus: 1,
107+
PollTimeout: 90 * time.Second,
106108
TargetSHA: g.SHA,
107109
}
108-
g.Cnx.Clients.Log.Info("Waiting for Repository to be updated")
109-
_, err = twait.UntilRepositoryUpdated(ctx, g.Cnx.Clients, waitOpts)
110+
111+
g.Cnx.Clients.Log.Info("Waiting for PipelineRun to be cancelled")
112+
err = twait.UntilPipelineRunHasReason(ctx, g.Cnx.Clients, tektonv1.PipelineRunReasonCancelled, cancelWaitOpts)
110113
assert.NilError(t, err)
111114

112-
g.Cnx.Clients.Log.Infof("Check if we have the repository set as succeeded")
113-
repo, err := g.Cnx.Clients.PipelineAsCode.PipelinesascodeV1alpha1().Repositories(g.TargetNamespace).Get(ctx, g.TargetNamespace, metav1.GetOptions{})
115+
g.Cnx.Clients.Log.Info("Waiting for Repository status to reflect cancellation")
116+
_, err = twait.UntilRepositoryHasStatusReason(ctx, g.Cnx.Clients, cancelWaitOpts, tektonv1.PipelineRunReasonCancelled.String())
114117
assert.NilError(t, err)
115-
assert.Equal(t, repo.Status[len(repo.Status)-1].Conditions[0].Status, corev1.ConditionFalse)
116118

117119
pruns, err = g.Cnx.Clients.Tekton.TektonV1().PipelineRuns(g.TargetNamespace).List(ctx, metav1.ListOptions{
118120
LabelSelector: fmt.Sprintf("%s=%s", keys.SHA, g.SHA),

0 commit comments

Comments
 (0)