Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix finally e2e test #3464

Merged
merged 1 commit into from
Oct 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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