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

Initialize load testing #3554

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 2 additions & 2 deletions test/duplicate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"knative.dev/pkg/test/helpers"
)

// TestDuplicatePodTaskRun creates 10 builds and checks that each of them has only one build pod.
// TestDuplicatePodTaskRun creates 25 builds and checks that each of them has only one build pod.
func TestDuplicatePodTaskRun(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -67,7 +67,7 @@ func TestDuplicatePodTaskRun(t *testing.T) {
go func(t *testing.T) {
defer wg.Done()

if err := WaitForTaskRunState(ctx, c, taskrunName, TaskRunSucceed(taskrunName), "TaskRunDuplicatePodTaskRunFailed"); err != nil {
if err := WaitForTaskRunState(ctx, c, taskrunName, TaskRunSucceed(taskrunName), "TaskRunDuplicatePodTaskRunSuccess"); err != nil {
t.Errorf("Error waiting for TaskRun to finish: %s", err)
return
}
Expand Down
2 changes: 1 addition & 1 deletion test/init_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build conformance e2e examples
// +build conformance e2e examples load

/*
Copyright 2019 The Tekton Authors
Expand Down
69 changes: 69 additions & 0 deletions test/load-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash

# Copyright 2019 The Tekton Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script calls out to scripts in tektoncd/plumbing to setup a cluster
# and deploy Tekton Pipelines to it for running integration tests.

source $(git rev-parse --show-toplevel)/vendor/github.com/tektoncd/plumbing/scripts/library.sh

function fail_test() {
echo "***************************************"
echo "*** LOAD TESTS FAILED ***"
echo "*** Start of information dump ***"
echo "***************************************"
echo ">>> All resources:"
kubectl get all --all-namespaces
echo ">>> Services:"
kubectl get services --all-namespaces
echo ">>> Events:"
kubectl get events --all-namespaces
function_exists dump_extra_cluster_state && dump_extra_cluster_state
echo "***************************************"
echo "*** LOAD TESTS FAILED ***"
echo "*** End of information dump ***"
echo "***************************************"
exit 1
}

function success() {
echo "**************************************"
echo "*** LOAD TESTS PASSED ***"
echo "**************************************"
exit 0
}

TIMEOUT="10m"
TASKRUN_NUM=50

while [[ $# -ne 0 ]]; do
parameter=$1
[[ $# -ge 2 ]] || abort "missing parameter after $1"
shift
case ${parameter} in
--timeout) TIMEOUT=$1 ;;
--taskrun-num) TASKRUN_NUM=$1 ;;
*) abort "unknown option ${parameter}" ;;
esac
shift
done

# Script entry point.
header "Running load tests"

report_go_test -tags load -timeout ${TIMEOUT} ./test/ -taskrun-num ${TASKRUN_NUM} || failed=1

(( failed )) && fail_test
success
80 changes: 80 additions & 0 deletions test/load_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// +build load

/*
Copyright 2020 The Tekton Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package test

import (
"context"
"flag"
"sync"
"testing"

"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
knativetest "knative.dev/pkg/test"
"knative.dev/pkg/test/helpers"
)

var (
taskrunNum = flag.Int("taskrun-num", 50, "Number of TaskRun")
)

// TestPerformance creates multiple builds and checks that each of them has only one build pod.
func TestPerformance(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c, namespace := setup(ctx, t)

knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf)
defer tearDown(ctx, t, c, namespace)

var wg sync.WaitGroup
for i := 0; i < *taskrunNum; i++ {
wg.Add(1)
taskrunName := helpers.ObjectNameForTest(t)
t.Logf("Creating taskrun %q.", taskrunName)

taskrun := &v1beta1.TaskRun{
ObjectMeta: metav1.ObjectMeta{Name: taskrunName, Namespace: namespace},
Spec: v1beta1.TaskRunSpec{
TaskSpec: &v1beta1.TaskSpec{
Steps: []v1beta1.Step{{Container: corev1.Container{
Image: "busybox",
Command: []string{"/bin/echo"},
Args: []string{"simple"},
}}},
},
},
}
if _, err := c.TaskRunClient.Create(ctx, taskrun, metav1.CreateOptions{}); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for creating the TaskRun synchronously ?

t.Fatalf("Error creating taskrun: %v", err)
}
go func(t *testing.T) {
defer wg.Done()

if err := WaitForTaskRunState(ctx, c, taskrunName, TaskRunSucceed(taskrunName), "TaskRunDuplicatePodTaskRunSuccess"); err != nil {
t.Errorf("Error waiting for TaskRun to finish: %s", err)
return
}
}(t)
}
wg.Wait()
}