Skip to content

Commit

Permalink
fix finally e2e test
Browse files Browse the repository at this point in the history
There was a bug in retrieving a list of taskRuns. All the names were
instrumented but listing taskruns for a pipelineRun was still using
old pipelineRun name which was causing an empty list of taskRuns and
in turn resulting in skipping all the validations. Fixed the call
where all the taskRuns are being retrieved for the pipelineRun.
And now since the taskRun names are no longer predictable, iterate over
the taskRuns and distinguish them based on the label tekton.dev/pipelineTask.
  • Loading branch information
pritidesai authored and tekton-robot committed Oct 29, 2020
1 parent 0df5c32 commit b405d86
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions test/pipelinefinally_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package test

import (
"context"
"strings"
"testing"

"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
Expand Down Expand Up @@ -88,31 +87,31 @@ func TestPipelineLevelFinally_OneDAGTaskFailed_Failure(t *testing.T) {
t.Fatalf("Waiting for PipelineRun %s to fail: %v", pipelineRun.Name, err)
}

taskrunList, err := c.TaskRunClient.List(ctx, metav1.ListOptions{LabelSelector: "tekton.dev/pipelineRun=pipelinerun-failed-dag-tasks"})
taskrunList, err := c.TaskRunClient.List(ctx, metav1.ListOptions{LabelSelector: "tekton.dev/pipelineRun=" + pipelineRun.Name})
if err != nil {
t.Fatalf("Error listing TaskRuns for PipelineRun %s: %s", pipelineRun.Name, err)
}

var dagTask1EndTime, dagTask2EndTime, finalTaskStartTime *metav1.Time
// verify dag task failed, parallel dag task succeeded, and final task succeeded
for _, taskrunItem := range taskrunList.Items {
switch n := taskrunItem.Name; {
case strings.HasPrefix(n, "pipelinerun-failed-dag-tasks-dagtask1"):
switch n := taskrunItem.Labels["tekton.dev/pipelineTask"]; {
case n == "dagtask1":
if !isFailed(t, n, taskrunItem.Status.Conditions) {
t.Fatalf("TaskRun %s for dag task should have failed", n)
t.Fatalf("dag task %s should have failed", n)
}
dagTask1EndTime = taskrunItem.Status.CompletionTime
case strings.HasPrefix(n, "pipelinerun-failed-dag-tasks-dagtask2"):
if err := WaitForTaskRunState(ctx, c, n, TaskRunSucceed(n), "TaskRunSuccess"); err != nil {
case n == "dagtask2":
if err := WaitForTaskRunState(ctx, c, taskrunItem.Name, TaskRunSucceed(taskrunItem.Name), "TaskRunSuccess"); err != nil {
t.Errorf("Error waiting for TaskRun to succeed: %v", err)
}
dagTask2EndTime = taskrunItem.Status.CompletionTime
case strings.HasPrefix(n, "pipelinerun-failed-dag-tasks-dagtask3"):
case n == "dagtask3":
if !isSkipped(t, n, taskrunItem.Status.Conditions) {
t.Fatalf("TaskRun %s for dag task should have skipped due to condition failure", n)
t.Fatalf("dag task %s should have skipped due to condition failure", n)
}
case strings.HasPrefix(n, "pipelinerun-failed-dag-tasks-finaltask1"):
if err := WaitForTaskRunState(ctx, c, n, TaskRunSucceed(n), "TaskRunSuccess"); err != nil {
case n == "finaltask1":
if err := WaitForTaskRunState(ctx, c, taskrunItem.Name, TaskRunSucceed(taskrunItem.Name), "TaskRunSuccess"); err != nil {
t.Errorf("Error waiting for TaskRun to succeed: %v", err)
}
finalTaskStartTime = taskrunItem.Status.StartTime
Expand Down Expand Up @@ -168,21 +167,21 @@ func TestPipelineLevelFinally_OneFinalTaskFailed_Failure(t *testing.T) {
t.Fatalf("PipelineRun execution failed")
}

taskrunList, err := c.TaskRunClient.List(ctx, metav1.ListOptions{LabelSelector: "tekton.dev/pipelineRun=pipelinerun-failed-final-tasks"})
taskrunList, err := c.TaskRunClient.List(ctx, metav1.ListOptions{LabelSelector: "tekton.dev/pipelineRun=" + pipelineRun.Name})
if err != nil {
t.Fatalf("Error listing TaskRuns for PipelineRun %s: %s", pipelineRun.Name, err)
}

// verify dag task succeeded and final task failed
for _, taskrunItem := range taskrunList.Items {
switch n := taskrunItem.Name; {
case strings.HasPrefix(n, "pipelinerun-failed-final-tasks-dagtask1"):
switch n := taskrunItem.Labels["tekton.dev/pipelineTask"]; {
case n == "dagtask1":
if !isSuccessful(t, n, taskrunItem.Status.Conditions) {
t.Fatalf("TaskRun %s for dag task should have succeeded", n)
t.Fatalf("dag task %s should have succeeded", n)
}
case strings.HasPrefix(n, "pipelinerun-failed-final-tasks-finaltask1"):
case n == "finaltask1":
if !isFailed(t, n, taskrunItem.Status.Conditions) {
t.Fatalf("TaskRun %s for final task should have failed", n)
t.Fatalf("final task %s should have failed", n)
}
default:
t.Fatalf("TaskRuns were not found for both final and dag tasks")
Expand Down

0 comments on commit b405d86

Please sign in to comment.