From 6d24de2c291883dfcc7bd9390aec243dbc4f7a8d Mon Sep 17 00:00:00 2001 From: Chmouel Boudjnah Date: Fri, 20 Mar 2026 09:42:35 +0100 Subject: [PATCH] fix: TestGHEPullRequestGitopsCommentCancel race MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- test/github_pullrequest_retest_test.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/test/github_pullrequest_retest_test.go b/test/github_pullrequest_retest_test.go index 3598d18b2f..8edf44a5ac 100644 --- a/test/github_pullrequest_retest_test.go +++ b/test/github_pullrequest_retest_test.go @@ -8,11 +8,13 @@ import ( "os" "strings" "testing" + "time" "github.com/google/go-github/v81/github" "github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/keys" tgithub "github.com/openshift-pipelines/pipelines-as-code/test/pkg/github" twait "github.com/openshift-pipelines/pipelines-as-code/test/pkg/wait" + tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "gotest.tools/v3/assert" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -102,21 +104,21 @@ func TestGithubGHEPullRequestGitopsCommentCancel(t *testing.T) { &github.IssueComment{Body: github.Ptr("/cancel pr-gitops-comment")}) assert.NilError(t, err) - waitOpts = twait.Opts{ + cancelWaitOpts := twait.Opts{ RepoName: g.TargetNamespace, Namespace: g.TargetNamespace, - MinNumberStatus: 3, - PollTimeout: twait.DefaultTimeout, + MinNumberStatus: 1, + PollTimeout: 90 * time.Second, TargetSHA: g.SHA, } - g.Cnx.Clients.Log.Info("Waiting for Repository to be updated") - _, err = twait.UntilRepositoryUpdated(ctx, g.Cnx.Clients, waitOpts) + + g.Cnx.Clients.Log.Info("Waiting for PipelineRun to be cancelled") + err = twait.UntilPipelineRunHasReason(ctx, g.Cnx.Clients, tektonv1.PipelineRunReasonCancelled, cancelWaitOpts) assert.NilError(t, err) - g.Cnx.Clients.Log.Infof("Check if we have the repository set as succeeded") - repo, err := g.Cnx.Clients.PipelineAsCode.PipelinesascodeV1alpha1().Repositories(g.TargetNamespace).Get(ctx, g.TargetNamespace, metav1.GetOptions{}) + g.Cnx.Clients.Log.Info("Waiting for Repository status to reflect cancellation") + _, err = twait.UntilRepositoryHasStatusReason(ctx, g.Cnx.Clients, cancelWaitOpts, tektonv1.PipelineRunReasonCancelled.String()) assert.NilError(t, err) - assert.Equal(t, repo.Status[len(repo.Status)-1].Conditions[0].Status, corev1.ConditionFalse) pruns, err = g.Cnx.Clients.Tekton.TektonV1().PipelineRuns(g.TargetNamespace).List(ctx, metav1.ListOptions{ LabelSelector: fmt.Sprintf("%s=%s", keys.SHA, g.SHA),