diff --git a/test/timeout_test.go b/test/timeout_test.go index edb0cf2f5e7..18b05f528c3 100644 --- a/test/timeout_test.go +++ b/test/timeout_test.go @@ -185,37 +185,40 @@ func TestTaskRunTimeout(t *testing.T) { c, namespace := setup(t) t.Parallel() + taskName := "giraffe" + taskRunName := "run-giraffe" + knativetest.CleanupOnInterrupt(func() { tearDown(t, c, namespace) }, t.Logf) defer tearDown(t, c, namespace) t.Logf("Creating Task and TaskRun in namespace %s", namespace) - if _, err := c.TaskClient.Create(tb.Task("giraffe", namespace, + if _, err := c.TaskClient.Create(tb.Task(taskName, namespace, tb.TaskSpec(tb.Step("amazing-busybox", "busybox", tb.Command("/bin/sh"), tb.Args("-c", "sleep 3000"))))); err != nil { - t.Fatalf("Failed to create Task `%s`: %s", "giraffe", err) + t.Fatalf("Failed to create Task `%s`: %s", taskName, err) } - if _, err := c.TaskRunClient.Create(tb.TaskRun("run-giraffe", namespace, tb.TaskRunSpec(tb.TaskRunTaskRef("giraffe"), + if _, err := c.TaskRunClient.Create(tb.TaskRun(taskRunName, namespace, tb.TaskRunSpec(tb.TaskRunTaskRef(taskName), // Do not reduce this timeout. Taskrun e2e test is also verifying // if reconcile is triggered from timeout handler and not by pod informers tb.TaskRunTimeout(30*time.Second)))); err != nil { - t.Fatalf("Failed to create TaskRun `%s`: %s", "run-giraffe", err) + t.Fatalf("Failed to create TaskRun `%s`: %s", taskRunName, err) } - t.Logf("Waiting for TaskRun %s in namespace %s to complete", "run-giraffe", namespace) - if err := WaitForTaskRunState(c, "run-giraffe", func(tr *v1alpha1.TaskRun) (bool, error) { + t.Logf("Waiting for TaskRun %s in namespace %s to complete", taskRunName, namespace) + if err := WaitForTaskRunState(c, taskRunName, func(tr *v1alpha1.TaskRun) (bool, error) { cond := tr.Status.GetCondition(duckv1alpha1.ConditionSucceeded) if cond != nil { if cond.Status == corev1.ConditionFalse { if cond.Reason == "TaskRunTimeout" { return true, nil } - return true, fmt.Errorf("taskRun %s completed with the wrong reason: %s", "run-giraffe", cond.Reason) + return true, fmt.Errorf("taskRun %s completed with the wrong reason: %s", taskRunName, cond.Reason) } else if cond.Status == corev1.ConditionTrue { - return true, fmt.Errorf("taskRun %s completed successfully, should have been timed out", "run-giraffe") + return true, fmt.Errorf("taskRun %s completed successfully, should have been timed out", taskRunName) } } return false, nil }, "TaskRunTimeout"); err != nil { - t.Errorf("Error waiting for TaskRun %s to finish: %s", "run-giraffe", err) + t.Errorf("Error waiting for TaskRun %s to finish: %s", taskRunName, err) } }