-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathtimeout_test.go
562 lines (507 loc) · 20.3 KB
/
timeout_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
//go:build e2e
// +build e2e
/*
Copyright 2021 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"
"fmt"
"strings"
"sync"
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/test/parse"
corev1 "k8s.io/api/core/v1"
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
// verify that pipelinerun timeout works and leads to the correct TaskRun statuses
// and pod deletions.
func TestPipelineRunTimeout(t *testing.T) {
t.Parallel()
// cancel the context after we have waited a suitable buffer beyond the given deadline.
ctx, cancel := context.WithTimeout(context.Background(), timeout+2*time.Minute)
defer cancel()
c, namespace := setup(ctx, t)
knativetest.CleanupOnInterrupt(func() { tearDown(context.Background(), t, c, namespace) }, t.Logf)
defer tearDown(context.Background(), t, c, namespace)
t.Logf("Creating Task in namespace %s", namespace)
task := parse.MustParseV1beta1Task(t, fmt.Sprintf(`
metadata:
name: %s
namespace: %s
spec:
steps:
- image: busybox
command: ['/bin/sh']
args: ['-c', 'sleep 10']
`, helpers.ObjectNameForTest(t), namespace))
if _, err := c.V1beta1TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", task.Name, err)
}
pipeline := parse.MustParseV1beta1Pipeline(t, fmt.Sprintf(`
metadata:
name: %s
namespace: %s
spec:
tasks:
- name: foo
taskRef:
name: %s
`, helpers.ObjectNameForTest(t), namespace, task.Name))
pipelineRun := parse.MustParseV1beta1PipelineRun(t, fmt.Sprintf(`
metadata:
name: %s
namespace: %s
spec:
pipelineRef:
name: %s
timeout: 5s
`, helpers.ObjectNameForTest(t), namespace, pipeline.Name))
if _, err := c.V1beta1PipelineClient.Create(ctx, pipeline, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Pipeline `%s`: %s", pipeline.Name, err)
}
if _, err := c.V1beta1PipelineRunClient.Create(ctx, pipelineRun, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create PipelineRun `%s`: %s", pipelineRun.Name, err)
}
t.Logf("Waiting for PipelineRun %s in namespace %s to be timed out", pipelineRun.Name, namespace)
if err := WaitForPipelineRunState(ctx, c, pipelineRun.Name, timeout, FailedWithReason(v1beta1.PipelineRunReasonTimedOut.String(), pipelineRun.Name), "PipelineRunTimedOut", v1beta1Version); err != nil {
t.Errorf("Error waiting for PipelineRun %s to finish: %s", pipelineRun.Name, err)
}
taskrunList, err := c.V1beta1TaskRunClient.List(ctx, metav1.ListOptions{LabelSelector: fmt.Sprintf("tekton.dev/pipelineRun=%s", pipelineRun.Name)})
if err != nil {
t.Fatalf("Error listing TaskRuns for PipelineRun %s: %s", pipelineRun.Name, err)
}
t.Logf("Waiting for PipelineRun %s in namespace %s to be timed out", pipelineRun.Name, namespace)
if err := WaitForPipelineRunState(ctx, c, pipelineRun.Name, timeout, FailedWithReason(v1beta1.PipelineRunReasonTimedOut.String(), pipelineRun.Name), "PipelineRunTimedOut", v1beta1Version); err != nil {
t.Errorf("Error waiting for PipelineRun %s to finish: %s", pipelineRun.Name, err)
}
t.Logf("Waiting for TaskRuns from PipelineRun %s in namespace %s to time out and be cancelled", pipelineRun.Name, namespace)
var wg sync.WaitGroup
for _, taskrunItem := range taskrunList.Items {
wg.Add(1)
go func(name string) {
defer wg.Done()
err := WaitForTaskRunState(ctx, c, name, FailedWithReason(v1beta1.TaskRunReasonCancelled.String(), name), v1beta1.TaskRunReasonCancelled.String(), v1beta1Version)
if err != nil {
t.Errorf("Error waiting for TaskRun %s to timeout: %s", name, err)
}
}(taskrunItem.Name)
}
wg.Wait()
if _, err := c.V1beta1PipelineRunClient.Get(ctx, pipelineRun.Name, metav1.GetOptions{}); err != nil {
t.Fatalf("Failed to get PipelineRun `%s`: %s", pipelineRun.Name, err)
}
// Verify that we can create a second Pipeline using the same Task without a Pipeline-level timeout that will not
// time out
secondPipeline := parse.MustParseV1beta1Pipeline(t, fmt.Sprintf(`
metadata:
name: %s
namespace: %s
spec:
tasks:
- name: foo
taskRef:
name: %s
`, helpers.ObjectNameForTest(t), namespace, task.Name))
secondPipelineRun := parse.MustParseV1beta1PipelineRun(t, fmt.Sprintf(`
metadata:
name: %s
namespace: %s
spec:
pipelineRef:
name: %s
`, helpers.ObjectNameForTest(t), namespace, secondPipeline.Name))
if _, err := c.V1beta1PipelineClient.Create(ctx, secondPipeline, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Pipeline `%s`: %s", secondPipeline.Name, err)
}
if _, err := c.V1beta1PipelineRunClient.Create(ctx, secondPipelineRun, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create PipelineRun `%s`: %s", secondPipelineRun.Name, err)
}
t.Logf("Waiting for PipelineRun %s in namespace %s to complete", secondPipelineRun.Name, namespace)
if err := WaitForPipelineRunState(ctx, c, secondPipelineRun.Name, timeout, PipelineRunSucceed(secondPipelineRun.Name), "PipelineRunSuccess", v1beta1Version); err != nil {
t.Fatalf("Error waiting for PipelineRun %s to finish: %s", secondPipelineRun.Name, err)
}
}
// TestStepTimeout is an integration test that will verify a Step can be timed out.
func TestStepTimeout(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
c, namespace := setup(ctx, t)
knativetest.CleanupOnInterrupt(func() { tearDown(context.Background(), t, c, namespace) }, t.Logf)
defer tearDown(context.Background(), t, c, namespace)
t.Logf("Creating Task with Step step-no-timeout, Step step-timeout, and Step step-canceled in namespace %s", namespace)
taskRun := parse.MustParseV1beta1TaskRun(t, fmt.Sprintf(`
metadata:
name: %s
namespace: %s
spec:
taskSpec:
steps:
- name: no-timeout
image: busybox
script: sleep 1
timeout: 2s
- name: timeout
image: busybox
script: sleep 1
timeout: 1ms
- name: canceled
image: busybox
script: sleep 1
`, helpers.ObjectNameForTest(t), namespace))
t.Logf("Creating TaskRun %s in namespace %s", taskRun.Name, namespace)
if _, err := c.V1beta1TaskRunClient.Create(ctx, taskRun, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create TaskRun `%s`: %s", taskRun.Name, err)
}
failMsg := "\"step-timeout\" exited because the step exceeded the specified timeout limit"
t.Logf("Waiting for %s in namespace %s to time out", "step-timeout", namespace)
if err := WaitForTaskRunState(ctx, c, taskRun.Name, FailedWithMessage(failMsg, taskRun.Name), "StepTimeout", v1beta1Version); err != nil {
t.Logf("Error in taskRun %s status: %s\n", taskRun.Name, err)
t.Errorf("Expected: %s", failMsg)
}
tr, err := c.V1beta1TaskRunClient.Get(ctx, taskRun.Name, metav1.GetOptions{})
if err != nil {
t.Errorf("Error getting Taskrun: %v", err)
}
if tr == nil {
t.Fatalf("no TaskRun details available")
}
if tr.Status.Steps[0].Terminated == nil {
t.Errorf("step-no-timeout should have Completed.")
} else if tr.Status.Steps[0].Terminated.Reason != "Completed" {
t.Errorf("step-no-timeout should not have been terminated")
}
if tr.Status.Steps[2].Terminated == nil {
t.Errorf("step-canceled should have been canceled after step-timeout timed out")
} else if exitcode := tr.Status.Steps[2].Terminated.ExitCode; exitcode != 1 {
t.Logf("step-canceled exited with exit code %d, expected exit code 1", exitcode)
}
}
// TestStepTimeoutWithWS is an integration test that will verify a Step can be timed out.
func TestStepTimeoutWithWS(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
c, namespace := setup(ctx, t)
knativetest.CleanupOnInterrupt(func() { tearDown(context.Background(), t, c, namespace) }, t.Logf)
defer tearDown(context.Background(), t, c, namespace)
taskRun := parse.MustParseV1beta1TaskRun(t, `
metadata:
name: taskrun-with-timeout-step
spec:
workspaces:
- name: test
emptyDir: {}
taskSpec:
workspaces:
- name: test
steps:
- name: timeout
image: busybox
script: sleep 1
timeout: 1ms`)
t.Logf("Creating TaskRun %s in namespace %s", taskRun.Name, namespace)
if _, err := c.V1beta1TaskRunClient.Create(ctx, taskRun, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create TaskRun `%s`: %s", taskRun.Name, err)
}
failMsg := "\"step-timeout\" exited because the step exceeded the specified timeout limit"
t.Logf("Waiting for %s in namespace %s to time out", "step-timeout", namespace)
if err := WaitForTaskRunState(ctx, c, taskRun.Name, FailedWithMessage(failMsg, taskRun.Name), "StepTimeout", v1beta1Version); err != nil {
t.Logf("Error in taskRun %s status: %s\n", taskRun.Name, err)
t.Errorf("Expected: %s", failMsg)
}
}
// TestTaskRunTimeout is an integration test that will verify a TaskRun can be timed out.
func TestTaskRunTimeout(t *testing.T) {
t.Parallel()
timeout := 1 * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout+2*time.Minute)
defer cancel()
c, namespace := setup(ctx, t)
knativetest.CleanupOnInterrupt(func() { tearDown(context.Background(), t, c, namespace) }, t.Logf)
defer tearDown(context.Background(), t, c, namespace)
t.Logf("Creating Task and TaskRun in namespace %s", namespace)
task := parse.MustParseV1beta1Task(t, fmt.Sprintf(`
metadata:
name: %s
namespace: %s
spec:
steps:
- image: busybox
command: ['/bin/sh']
args: ['-c', 'sleep 3000']
`, helpers.ObjectNameForTest(t), namespace))
if _, err := c.V1beta1TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", task.Name, err)
}
taskRun := parse.MustParseV1beta1TaskRun(t, fmt.Sprintf(`
metadata:
name: %s
namespace: %s
spec:
taskRef:
name: %s
timeout: %s
`, helpers.ObjectNameForTest(t), namespace, task.Name, timeout))
if _, err := c.V1beta1TaskRunClient.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", taskRun.Name, namespace)
if err := WaitForTaskRunState(ctx, c, taskRun.Name, FailedWithReason(v1beta1.TaskRunReasonTimedOut.String(), taskRun.Name), v1beta1.TaskRunReasonTimedOut.String(), v1beta1Version); err != nil {
t.Errorf("Error waiting for TaskRun %s to finish: %s", taskRun.Name, err)
}
tr, err := c.V1beta1TaskRunClient.Get(ctx, taskRun.Name, metav1.GetOptions{})
if err != nil {
t.Errorf("Error retrieving TaskRun %s: %v", taskRun.Name, err)
}
for _, step := range tr.Status.Steps {
if step.Terminated == nil {
t.Errorf("TaskRun %s step %s does not have a terminated state but should", taskRun.Name, step.Name)
}
if d := cmp.Diff(step.Terminated.Reason, v1beta1.TaskRunReasonTimedOut.String()); d != "" {
t.Fatalf("-got, +want: %v", d)
}
}
}
func TestPipelineTaskTimeout(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), timeout+2*time.Minute)
defer cancel()
c, namespace := setup(ctx, t)
knativetest.CleanupOnInterrupt(func() { tearDown(context.Background(), t, c, namespace) }, t.Logf)
defer tearDown(context.Background(), t, c, namespace)
t.Logf("Creating Tasks in namespace %s", namespace)
task1 := parse.MustParseV1beta1Task(t, fmt.Sprintf(`
metadata:
name: %s
namespace: %s
spec:
steps:
- image: busybox
command: ['/bin/sh']
args: ['-c', 'sleep 1s']
`, helpers.ObjectNameForTest(t), namespace))
task2 := parse.MustParseV1beta1Task(t, fmt.Sprintf(`
metadata:
name: %s
namespace: %s
spec:
steps:
- image: busybox
command: ['/bin/sh']
args: ['-c', 'sleep 10s']
`, helpers.ObjectNameForTest(t), namespace))
if _, err := c.V1beta1TaskClient.Create(ctx, task1, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", task1.Name, err)
}
if _, err := c.V1beta1TaskClient.Create(ctx, task2, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", task2.Name, err)
}
pipeline := parse.MustParseV1beta1Pipeline(t, fmt.Sprintf(`
metadata:
name: %s
namespace: %s
spec:
tasks:
- name: pipelinetask1
taskRef:
name: %s
timeout: 60s
- name: pipelinetask2
taskRef:
name: %s
timeout: 5s
`, helpers.ObjectNameForTest(t), namespace, task1.Name, task2.Name))
pipelineRun := parse.MustParseV1beta1PipelineRun(t, fmt.Sprintf(`
metadata:
name: %s
namespace: %s
spec:
pipelineRef:
name: %s
`, helpers.ObjectNameForTest(t), namespace, pipeline.Name))
if _, err := c.V1beta1PipelineClient.Create(ctx, pipeline, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Pipeline `%s`: %s", pipeline.Name, err)
}
if _, err := c.V1beta1PipelineRunClient.Create(ctx, pipelineRun, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create PipelineRun `%s`: %s", pipelineRun.Name, err)
}
t.Logf("Waiting for PipelineRun %s with PipelineTask timeout in namespace %s to fail", pipelineRun.Name, namespace)
if err := WaitForPipelineRunState(ctx, c, pipelineRun.Name, timeout, FailedWithReason(v1beta1.PipelineRunReasonFailed.String(), pipelineRun.Name), "PipelineRunTimedOut", v1beta1Version); err != nil {
t.Fatalf("Error waiting for PipelineRun %s to finish: %s", pipelineRun.Name, err)
}
taskrunList, err := c.V1beta1TaskRunClient.List(ctx, metav1.ListOptions{LabelSelector: fmt.Sprintf("tekton.dev/pipelineRun=%s", pipelineRun.Name)})
if err != nil {
t.Fatalf("Error listing TaskRuns for PipelineRun %s: %s", pipelineRun.Name, err)
}
t.Logf("Waiting for TaskRun from PipelineRun %s in namespace %s to be timed out", pipelineRun.Name, namespace)
var wg sync.WaitGroup
for _, taskrunItem := range taskrunList.Items {
wg.Add(1)
go func(tr v1beta1.TaskRun) {
defer wg.Done()
name := tr.Name
err := WaitForTaskRunState(ctx, c, name, func(ca apis.ConditionAccessor) (bool, error) {
cond := ca.GetCondition(apis.ConditionSucceeded)
if cond != nil {
if tr.Spec.TaskRef.Name == task1.Name && cond.Status == corev1.ConditionTrue {
if cond.Reason == "Succeeded" {
return true, nil
}
return true, fmt.Errorf("taskRun %q completed with the wrong reason: %s", task1.Name, cond.Reason)
} else if tr.Spec.TaskRef.Name == task1.Name && cond.Status == corev1.ConditionFalse {
return true, fmt.Errorf("taskRun %q failed, but should have been Succeeded", name)
}
if tr.Spec.TaskRef.Name == task2.Name && cond.Status == corev1.ConditionFalse {
if cond.Reason == v1beta1.TaskRunReasonTimedOut.String() {
return true, nil
}
return true, fmt.Errorf("taskRun %q completed with the wrong reason: %s", task2.Name, cond.Reason)
} else if tr.Spec.TaskRef.Name == task2.Name && cond.Status == corev1.ConditionTrue {
return true, fmt.Errorf("taskRun %q should have timed out", name)
}
}
return false, nil
}, v1beta1.TaskRunReasonCancelled.String(), v1beta1Version)
if err != nil {
t.Errorf("Error waiting for TaskRun %s to timeout: %s", name, err)
}
}(taskrunItem)
}
wg.Wait()
}
// TestPipelineRunTasksTimeout is an integration test that will
// verify that pipelinerun tasksTimeout works and leads to the correct PipelineRun and TaskRun statuses
// and pod deletions.
func TestPipelineRunTasksTimeout(t *testing.T) {
t.Parallel()
// cancel the context after we have waited a suitable buffer beyond the given deadline.
ctx, cancel := context.WithTimeout(context.Background(), timeout+2*time.Minute)
defer cancel()
c, namespace := setup(ctx, t)
knativetest.CleanupOnInterrupt(func() { tearDown(context.Background(), t, c, namespace) }, t.Logf)
defer tearDown(context.Background(), t, c, namespace)
t.Logf("Creating Task in namespace %s", namespace)
task := parse.MustParseV1beta1Task(t, fmt.Sprintf(`
metadata:
name: %s
namespace: %s
spec:
steps:
- image: busybox
command: ['/bin/sh']
args: ['-c', 'sleep 30']
`, helpers.ObjectNameForTest(t), namespace))
if _, err := c.V1beta1TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", task.Name, err)
}
t.Logf("Creating Finally Task in namespace %s", namespace)
fTask := parse.MustParseV1beta1Task(t, fmt.Sprintf(`
metadata:
name: %s
namespace: %s
spec:
steps:
- image: busybox
command: ['/bin/sh']
args: ['-c', 'sleep 1']
`, helpers.ObjectNameForTest(t), namespace))
if _, err := c.V1beta1TaskClient.Create(ctx, fTask, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", fTask.Name, err)
}
pipeline := parse.MustParseV1beta1Pipeline(t, fmt.Sprintf(`
metadata:
name: %s
namespace: %s
spec:
tasks:
- name: dagtask
taskRef:
name: %s
finally:
- name: finallytask
taskRef:
name: %s
`, helpers.ObjectNameForTest(t), namespace, task.Name, fTask.Name))
pipelineRun := parse.MustParseV1beta1PipelineRun(t, fmt.Sprintf(`
metadata:
name: %s
namespace: %s
spec:
pipelineRef:
name: %s
timeouts:
pipeline: 60s
tasks: 20s
finally: 20s
`, helpers.ObjectNameForTest(t), namespace, pipeline.Name))
if _, err := c.V1beta1PipelineClient.Create(ctx, pipeline, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create Pipeline `%s`: %s", pipeline.Name, err)
}
if _, err := c.V1beta1PipelineRunClient.Create(ctx, pipelineRun, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create PipelineRun `%s`: %s", pipelineRun.Name, err)
}
t.Logf("Waiting for PipelineRun %s in namespace %s to be failed", pipelineRun.Name, namespace)
if err := WaitForPipelineRunState(ctx, c, pipelineRun.Name, timeout, FailedWithReason(v1beta1.PipelineRunReasonFailed.String(), pipelineRun.Name), "PipelineRunFailed", v1beta1Version); err != nil {
t.Errorf("Error waiting for PipelineRun %s to finish: %s", pipelineRun.Name, err)
}
taskrunList, err := c.V1beta1TaskRunClient.List(ctx, metav1.ListOptions{LabelSelector: fmt.Sprintf("tekton.dev/pipelineRun=%s", pipelineRun.Name)})
if err != nil {
t.Fatalf("Error listing TaskRuns for PipelineRun %s: %s", pipelineRun.Name, err)
}
t.Logf("Waiting for TaskRun from PipelineRun %s in namespace %s to time out and finally TaskRun to be successful", pipelineRun.Name, namespace)
var wg sync.WaitGroup
for _, taskrunItem := range taskrunList.Items {
wg.Add(1)
go func(tr v1beta1.TaskRun) {
defer wg.Done()
name := tr.Name
err := WaitForTaskRunState(ctx, c, name, func(ca apis.ConditionAccessor) (bool, error) {
cond := ca.GetCondition(apis.ConditionSucceeded)
if cond != nil {
if tr.Spec.TaskRef.Name == fTask.Name && cond.Status == corev1.ConditionTrue {
if cond.Reason == "Succeeded" {
return true, nil
}
return true, fmt.Errorf("taskRun %q completed with the wrong reason: %s", fTask.Name, cond.Reason)
} else if tr.Spec.TaskRef.Name == fTask.Name && cond.Status == corev1.ConditionFalse {
return true, fmt.Errorf("taskRun %q failed, but should have been Succeeded", name)
}
if tr.Spec.TaskRef.Name == task.Name && cond.Status == corev1.ConditionFalse {
if !strings.Contains(cond.Message, string(v1beta1.TaskRunCancelledByPipelineTimeoutMsg)) {
return true, fmt.Errorf("taskRun %s completed with the wrong message: %s", task.Name, cond.Message)
}
if cond.Reason == v1beta1.TaskRunReasonCancelled.String() {
return true, nil
}
return true, fmt.Errorf("taskRun %q completed with the wrong reason: %s", task.Name, cond.Reason)
} else if tr.Spec.TaskRef.Name == task.Name && cond.Status == corev1.ConditionTrue {
return true, fmt.Errorf("taskRun %q should have timed out", name)
}
}
return false, nil
}, v1beta1.TaskRunReasonCancelled.String(), v1beta1Version)
if err != nil {
t.Errorf("Error waiting for TaskRun %s to timeout: %s", name, err)
}
}(taskrunItem)
}
wg.Wait()
}