Skip to content

Commit

Permalink
fix(e2e): stabilize TestTaskRunFailure test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
l-qing committed Sep 2, 2024
1 parent c910594 commit 5919d77
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions test/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 5919d77

Please sign in to comment.