forked from tektoncd/pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduplicate_test.go
84 lines (71 loc) · 2.42 KB
/
duplicate_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// +build e2e
/*
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.
*/
package test
import (
"fmt"
"sync"
"testing"
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
"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"
)
// TestDuplicatePodTaskRun creates 10 builds and checks that each of them has only one build pod.
func TestDuplicatePodTaskRun(t *testing.T) {
c, namespace := setup(t)
t.Parallel()
knativetest.CleanupOnInterrupt(func() { tearDown(t, c, namespace) }, t.Logf)
defer tearDown(t, c, namespace)
var wg sync.WaitGroup
for i := 0; i < 25; i++ {
wg.Add(1)
taskrunName := fmt.Sprintf("duplicate-pod-taskrun-%d", i)
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(taskrun); err != nil {
t.Fatalf("Error creating taskrun: %v", err)
}
go func(t *testing.T) {
defer wg.Done()
if err := WaitForTaskRunState(c, taskrunName, TaskRunSucceed(taskrunName), "TaskRunDuplicatePodTaskRunFailed"); err != nil {
t.Errorf("Error waiting for TaskRun to finish: %s", err)
return
}
pods, err := c.KubeClient.Kube.CoreV1().Pods(namespace).List(metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s", pipeline.GroupName+pipeline.TaskRunLabelKey, taskrunName),
})
if err != nil {
t.Errorf("Error getting TaskRun pod list: %v", err)
return
}
if n := len(pods.Items); n != 1 {
t.Errorf("Error matching the number of build pods: expecting 1 pod, got %d", n)
return
}
}(t)
}
wg.Wait()
}