From 5919d7747a80163642fd958a18ac5d23bec65e7f Mon Sep 17 00:00:00 2001 From: qingliu Date: Sat, 3 Aug 2024 18:16:53 +0800 Subject: [PATCH] fix(e2e): stabilize TestTaskRunFailure test Most of the time, if a middle step fails, the subsequent steps are immediately marked as skipped. However, in rare cases, the subsequent steps may not be marked as skipped in time. To ensure the stability of e2e, we adapted to this scenario. --- test/taskrun_test.go | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/test/taskrun_test.go b/test/taskrun_test.go index 9a77c7f9fad..0238975c72f 100644 --- a/test/taskrun_test.go +++ b/test/taskrun_test.go @@ -127,10 +127,33 @@ spec: Name: "unnamed-2", Container: "step-unnamed-2", }} + expectedStepNumber := len(expectedStepState) + if len(taskrun.Status.Steps) < expectedStepNumber { + t.Fatalf("expected at least %d steps, got %d", expectedStepNumber, len(taskrun.Status.Steps)) + } ignoreTerminatedFields := cmpopts.IgnoreFields(corev1.ContainerStateTerminated{}, "StartedAt", "FinishedAt", "ContainerID") ignoreStepFields := cmpopts.IgnoreFields(v1.StepState{}, "ImageID") - if d := cmp.Diff(taskrun.Status.Steps, expectedStepState, ignoreTerminatedFields, ignoreStepFields); d != "" { - t.Fatalf("-got, +want: %v", d) + lastStepIndex := len(expectedStepState) - 1 + for i := range lastStepIndex { + if d := cmp.Diff(taskrun.Status.Steps[i], expectedStepState[i], ignoreTerminatedFields, ignoreStepFields); d != "" { + t.Fatalf("-got, +want: %v", d) + } + } + + // Sometimes, the state of the last container in the Pod is still running, + // and the state content of the final step is not skipped. + // In this case, we should compare the state of the last step with the normal state. + otherLatestExpectedStepState := v1.StepState{ + Name: "unnamed-2", + Container: "step-unnamed-2", + } + + if d := cmp.Diff(taskrun.Status.Steps[lastStepIndex], expectedStepState[lastStepIndex], ignoreTerminatedFields, ignoreStepFields); d != "" { + t.Logf("-got, +want: %v", d) + // try to compare the state of the last step with the other state + if d := cmp.Diff(taskrun.Status.Steps[lastStepIndex], otherLatestExpectedStepState, ignoreTerminatedFields, ignoreStepFields); d != "" { + t.Fatalf("-got, +want: %v", d) + } } releaseAnnotation, ok := taskrun.Annotations[pod.ReleaseAnnotation]