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

Add logstream to v1alpha1 timeout_test.go #3426

Merged
merged 1 commit into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions test/v1alpha1/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
knativetest "knative.dev/pkg/test"
"knative.dev/pkg/test/logging"
"knative.dev/pkg/test/logstream"

// Mysteriously by k8s libs, or they fail to create `KubeClient`s from config. Apparently just importing it is enough. @_@ side effects @_@. https://github.com/kubernetes/client-go/issues/242
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
Expand All @@ -57,6 +58,10 @@ func setup(ctx context.Context, t *testing.T, fn ...func(context.Context, *testi

initializeLogsAndMetrics(t)

// Inline controller logs from SYSTEM_NAMESPACE into the t.Log output.
cancel := logstream.Start(t)
t.Cleanup(cancel)

c := newClients(t, knativetest.Flags.Kubeconfig, knativetest.Flags.Cluster, namespace)
createNamespace(ctx, t, namespace, c.KubeClient)
verifyServiceAccountExistence(ctx, t, namespace, c.KubeClient)
Expand Down
46 changes: 25 additions & 21 deletions test/v1alpha1/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
knativetest "knative.dev/pkg/test"
"knative.dev/pkg/test/helpers"
)

// TestPipelineRunTimeout is an integration test that will
Expand All @@ -46,16 +47,16 @@ func TestPipelineRunTimeout(t *testing.T) {
defer tearDown(context.Background(), t, c, namespace)

t.Logf("Creating Task in namespace %s", namespace)
task := tb.Task("banana", tb.TaskSpec(
task := tb.Task(helpers.ObjectNameForTest(t), tb.TaskSpec(
tb.Step("busybox", tb.StepCommand("/bin/sh"), tb.StepArgs("-c", "sleep 10"))))
if _, err := c.TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", "banana", err)
t.Fatalf("Failed to create Task %q: %s", task.Name, err)
}

pipeline := tb.Pipeline("tomatoes",
tb.PipelineSpec(tb.PipelineTask("foo", "banana")),
pipeline := tb.Pipeline(helpers.ObjectNameForTest(t),
tb.PipelineSpec(tb.PipelineTask("foo", task.Name)),
)
pipelineRun := tb.PipelineRun("pear", tb.PipelineRunSpec(pipeline.Name,
pipelineRun := tb.PipelineRun(helpers.ObjectNameForTest(t), tb.PipelineRunSpec(pipeline.Name,
tb.PipelineRunTimeout(5*time.Second),
))
if _, err := c.PipelineClient.Create(ctx, pipeline, metav1.CreateOptions{}); err != nil {
Expand Down Expand Up @@ -121,9 +122,9 @@ func TestPipelineRunTimeout(t *testing.T) {

// Verify that we can create a second Pipeline using the same Task without a Pipeline-level timeout that will not
// time out
secondPipeline := tb.Pipeline("peppers",
tb.PipelineSpec(tb.PipelineTask("foo", "banana")))
secondPipelineRun := tb.PipelineRun("kiwi", tb.PipelineRunSpec("peppers"))
secondPipeline := tb.Pipeline(helpers.ObjectNameForTest(t),
tb.PipelineSpec(tb.PipelineTask("foo", task.Name)))
secondPipelineRun := tb.PipelineRun(helpers.ObjectNameForTest(t), tb.PipelineRunSpec(secondPipeline.Name))
if _, err := c.PipelineClient.Create(ctx, secondPipeline, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Pipeline `%s`: %s", secondPipeline.Name, err)
}
Expand All @@ -148,20 +149,23 @@ func TestTaskRunTimeout(t *testing.T) {
defer tearDown(context.Background(), t, c, namespace)

t.Logf("Creating Task and TaskRun in namespace %s", namespace)
if _, err := c.TaskClient.Create(ctx, tb.Task("giraffe",
tb.TaskSpec(tb.Step("busybox", tb.StepCommand("/bin/sh"), tb.StepArgs("-c", "sleep 3000")))), metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", "giraffe", err)
task := tb.Task(helpers.ObjectNameForTest(t),
tb.TaskSpec(tb.Step("busybox", tb.StepCommand("/bin/sh"), tb.StepArgs("-c", "sleep 3000"))))
if _, err := c.TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", task.Name, err)
}
if _, err := c.TaskRunClient.Create(ctx, tb.TaskRun("run-giraffe", tb.TaskRunSpec(tb.TaskRunTaskRef("giraffe"),

taskRun := tb.TaskRun(helpers.ObjectNameForTest(t), tb.TaskRunSpec(tb.TaskRunTaskRef(task.Name),
// 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))), metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create TaskRun `%s`: %s", "run-giraffe", err)
tb.TaskRunTimeout(30*time.Second)))
if _, err := c.TaskRunClient.Create(ctx, taskRun, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create TaskRun `%s`: %s", taskRun.Name, err)
}

t.Logf("Waiting for TaskRun %s in namespace %s to complete", "run-giraffe", namespace)
if err := WaitForTaskRunState(ctx, c, "run-giraffe", FailedWithReason("TaskRunTimeout", "run-giraffe"), "TaskRunTimeout"); err != nil {
t.Errorf("Error waiting for TaskRun %s to finish: %s", "run-giraffe", err)
t.Logf("Waiting for TaskRun %s in namespace %s to complete", taskRun.Name, namespace)
if err := WaitForTaskRunState(ctx, c, taskRun.Name, FailedWithReason("TaskRunTimeout", taskRun.Name), "TaskRunTimeout"); err != nil {
t.Errorf("Error waiting for TaskRun %s to finish: %s", taskRun.Name, err)
}
}

Expand All @@ -175,10 +179,10 @@ func TestPipelineTaskTimeout(t *testing.T) {
defer tearDown(context.Background(), t, c, namespace)

t.Logf("Creating Tasks in namespace %s", namespace)
task1 := tb.Task("success", tb.TaskSpec(
task1 := tb.Task(helpers.ObjectNameForTest(t), tb.TaskSpec(
tb.Step("busybox", tb.StepCommand("sleep"), tb.StepArgs("1s"))))

task2 := tb.Task("timeout", tb.TaskSpec(
task2 := tb.Task(helpers.ObjectNameForTest(t), tb.TaskSpec(
tb.Step("busybox", tb.StepCommand("sleep"), tb.StepArgs("10s"))))

if _, err := c.TaskClient.Create(ctx, task1, metav1.CreateOptions{}); err != nil {
Expand All @@ -188,14 +192,14 @@ func TestPipelineTaskTimeout(t *testing.T) {
t.Fatalf("Failed to create Task `%s`: %s", task2.Name, err)
}

pipeline := tb.Pipeline("pipelinetasktimeout",
pipeline := tb.Pipeline(helpers.ObjectNameForTest(t),
tb.PipelineSpec(
tb.PipelineTask("pipelinetask1", task1.Name, tb.PipelineTaskTimeout(60*time.Second)),
tb.PipelineTask("pipelinetask2", task2.Name, tb.PipelineTaskTimeout(5*time.Second)),
),
)

pipelineRun := tb.PipelineRun("prtasktimeout", tb.PipelineRunSpec(pipeline.Name))
pipelineRun := tb.PipelineRun(helpers.ObjectNameForTest(t), tb.PipelineRunSpec(pipeline.Name))

if _, err := c.PipelineClient.Create(ctx, pipeline, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Pipeline `%s`: %s", pipeline.Name, err)
Expand Down