Skip to content

Commit 3129fe0

Browse files
metlosfbm3307
authored andcommitted
increase the cleanup timeout for nstemplatetiers (codeready-toolchain#1161)
1 parent 47a2b0f commit 3129fe0

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

testsupport/cleanup/clean.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,21 @@ type AwaitilityInt interface {
4545

4646
// AddCleanTasks adds cleaning tasks for the given objects that will be automatically performed at the end of the test execution
4747
func AddCleanTasks(t *testing.T, cl client.Client, objects ...client.Object) {
48-
cleaning.addCleanTasks(t, cl, objects...)
48+
AddCleanTasksWithTimeout(t, cl, defaultTimeout, objects...)
4949
}
5050

51-
func (c *cleanManager) addCleanTasks(t *testing.T, cl client.Client, objects ...client.Object) {
51+
func AddCleanTasksWithTimeout(t *testing.T, cl client.Client, timeout time.Duration, objects ...client.Object) {
52+
cleaning.addCleanTasks(t, cl, timeout, objects...)
53+
}
54+
55+
func (c *cleanManager) addCleanTasks(t *testing.T, cl client.Client, timeout time.Duration, objects ...client.Object) {
5256
c.Lock()
5357
defer c.Unlock()
5458
for _, obj := range objects {
5559
if len(c.cleanTasks[t]) == 0 {
5660
t.Cleanup(c.clean(t))
5761
}
58-
c.cleanTasks[t] = append(c.cleanTasks[t], newCleanTask(t, cl, obj))
62+
c.cleanTasks[t] = append(c.cleanTasks[t], newCleanTask(t, cl, obj, timeout))
5963
}
6064
}
6165

@@ -94,16 +98,19 @@ type cleanTask struct {
9498
objToClean client.Object
9599
client client.Client
96100
t *testing.T
101+
timeout time.Duration
97102
}
98103

99104
func (c *cleanTask) clean() {
100105
c.Do(c.cleanObject)
101106
}
102-
func newCleanTask(t *testing.T, cl client.Client, obj client.Object) *cleanTask {
107+
108+
func newCleanTask(t *testing.T, cl client.Client, obj client.Object, timeout time.Duration) *cleanTask {
103109
return &cleanTask{
104110
t: t,
105111
client: cl,
106112
objToClean: obj,
113+
timeout: timeout,
107114
}
108115
}
109116

@@ -141,7 +148,7 @@ func (c *cleanTask) cleanObject() {
141148

142149
// wait until deletion is done
143150
c.t.Logf("waiting until %s: %s is completely deleted", kind, objToClean.GetName())
144-
err = wait.PollUntilContextTimeout(context.TODO(), defaultRetryInterval, defaultTimeout, true, func(ctx context.Context) (done bool, err error) {
151+
err = wait.PollUntilContextTimeout(context.TODO(), defaultRetryInterval, c.timeout, true, func(ctx context.Context) (done bool, err error) {
145152
if err := c.client.Get(context.TODO(), test.NamespacedName(objToClean.GetNamespace(), objToClean.GetName()), objToClean); err != nil {
146153
if errors.IsNotFound(err) {
147154
// if the object was UserSignup, then let's check that the MUR is deleted as well

testsupport/tiers/tier_setup.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"testing"
7+
"time"
78

89
toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
910
"github.com/codeready-toolchain/toolchain-common/pkg/configuration"
@@ -135,7 +136,8 @@ func CreateCustomNSTemplateTier(t *testing.T, hostAwait *wait.HostAwaitility, na
135136
err := modify(hostAwait, tier)
136137
require.NoError(t, err)
137138
}
138-
err := hostAwait.CreateWithCleanup(t, tier.NSTemplateTier)
139+
// NSTemplateTier can take a long time to delete because they wait for all their spaces to be deleted first...
140+
err := hostAwait.CreateWithCleanupTimeout(t, tier.NSTemplateTier, 2*time.Minute)
139141
require.NoError(t, err)
140142
newTTier, err := hostAwait.WaitForNSTemplateTier(t, tier.Name,
141143
wait.HasStatusTierTemplateRevisions(GetTemplateRefs(t, hostAwait, tier.Name).Flatten()))

testsupport/wait/awaitility.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,14 @@ func (a *Awaitility) CreateWithCleanup(t *testing.T, obj client.Object, opts ...
604604
return nil
605605
}
606606

607+
func (a *Awaitility) CreateWithCleanupTimeout(t *testing.T, obj client.Object, timeout time.Duration, opts ...client.CreateOption) error {
608+
if err := a.Client.Create(context.TODO(), obj, opts...); err != nil {
609+
return err
610+
}
611+
cleanup.AddCleanTasksWithTimeout(t, a.GetClient(), timeout, obj)
612+
return nil
613+
}
614+
607615
// Creates a copy of the object specified using the `from` parameter. The created copy is named using the `to` parameter and is cleaned up
608616
// after the test. The object can be modified using the optionally supplied modifiers before it is created. The `object` is an "output parameter"
609617
// that will contain the object as it was created in the cluster.

0 commit comments

Comments
 (0)