Skip to content

Commit 24313af

Browse files
committed
Fix TestGithubSecondPullRequestConcurrency test
Don't try to check the GitHub check runs, but instead check the status of the pipelinerun itself to make sure they are not kept as Pending (due of crash of the controller for example)
1 parent 9bfbf19 commit 24313af

File tree

1 file changed

+25
-45
lines changed

1 file changed

+25
-45
lines changed

test/github_pullrequest_concurrency_test.go

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,20 @@ import (
77
"context"
88
"fmt"
99
"net/http"
10-
"os"
1110
"testing"
1211
"time"
1312

14-
"github.com/google/go-github/v56/github"
1513
tgithub "github.com/openshift-pipelines/pipelines-as-code/test/pkg/github"
1614
"github.com/openshift-pipelines/pipelines-as-code/test/pkg/options"
1715
"github.com/openshift-pipelines/pipelines-as-code/test/pkg/payload"
1816
"github.com/openshift-pipelines/pipelines-as-code/test/pkg/wait"
17+
tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
1918
"github.com/tektoncd/pipeline/pkg/names"
2019
"gotest.tools/v3/assert"
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
)
2222

23-
func contains(s []string, e string) bool {
24-
for _, a := range s {
25-
if a == e {
26-
return true
27-
}
28-
}
29-
return false
30-
}
31-
3223
func TestGithubPullRequestConcurrency(t *testing.T) {
33-
if os.Getenv("NIGHTLY_E2E_TEST") != "true" {
34-
t.Skip("Skipping test since only enabled for nightly")
35-
}
36-
3724
ctx := context.Background()
3825
label := "Github PullRequest Concurrent"
3926
numberOfPipelineRuns := 10
@@ -91,41 +78,34 @@ func TestGithubPullRequestConcurrency(t *testing.T) {
9178
}
9279
assert.NilError(t, wait.UntilMinPRAppeared(ctx, runcnx.Clients, waitOpts, numberOfPipelineRuns))
9380

94-
runningChecks := 0
95-
finishedArray := []string{}
96-
for i := 0; i < 15; i++ {
97-
checkruns, _, err := ghcnx.Client.Checks.ListCheckRunsForRef(ctx, opts.Organization, opts.Repo, targetRefName, &github.ListCheckRunsOptions{})
81+
finished := false
82+
maxLoop := 15
83+
for i := 0; i < maxLoop; i++ {
84+
unsuccessful := 0
85+
prs, err := runcnx.Clients.Tekton.TektonV1().PipelineRuns(targetNS).List(ctx, metav1.ListOptions{})
9886
assert.NilError(t, err)
99-
if checkruns.Total == nil || *checkruns.Total < numberOfPipelineRuns {
100-
t.Logf("Waiting for all checks to be created: %d/%d", *checkruns.Total, numberOfPipelineRuns)
101-
time.Sleep(5 * time.Second)
102-
continue
103-
}
104-
assert.Assert(t, *checkruns.Total >= numberOfPipelineRuns)
105-
for _, checkrun := range checkruns.CheckRuns {
106-
cname := checkrun.GetName()
107-
switch {
108-
case checkrun.GetStatus() != "completed" && checkrun.GetConclusion() != "success":
109-
runcnx.Clients.Log.Infof("Waiting for CheckRun %s to be completed", cname)
110-
case checkrun.GetStatus() == "running":
111-
runningChecks++
112-
default:
113-
// check if cname is in finishedArray
114-
if !contains(finishedArray, cname) {
115-
runcnx.Clients.Log.Infof("PipelineRun %s has finished %d/%d",
116-
cname, len(finishedArray), numberOfPipelineRuns)
117-
finishedArray = append(finishedArray, cname)
87+
for _, pr := range prs.Items {
88+
if pr.Status.GetConditions() == nil {
89+
unsuccessful++
90+
continue
91+
}
92+
for _, condition := range pr.Status.GetConditions() {
93+
if condition.Status == "Unknown" || condition.GetReason() == tektonv1.PipelineRunSpecStatusPending {
94+
unsuccessful++
95+
continue
11896
}
11997
}
12098
}
121-
if len(finishedArray) == numberOfPipelineRuns {
99+
if unsuccessful == 0 {
100+
runcnx.Clients.Log.Infof("the %d pipelineruns has successfully finished", numberOfPipelineRuns)
101+
finished = true
122102
break
123103
}
124-
if runningChecks > maxNumberOfConcurrentPipelineRuns {
125-
runcnx.Clients.Log.Fatalf("Too many running checks %d our maxAmountOfConcurrentPRS == %d",
126-
runningChecks, numberOfPipelineRuns)
127-
}
128-
// it's high so we limit our ratelimitation
129-
time.Sleep(10 * time.Second)
104+
runcnx.Clients.Log.Infof("number of unsuccessful PR %d out of %d, waiting 10s more, %d/%d", unsuccessful, numberOfPipelineRuns*2, i, maxLoop)
105+
// it's high because it takes time to process on kind
106+
time.Sleep(15 * time.Second)
107+
}
108+
if !finished {
109+
t.Errorf("the %d pipelineruns has not successfully finished, some of them are still pending or it's abnormally slow to process the Q", numberOfPipelineRuns)
130110
}
131111
}

0 commit comments

Comments
 (0)