Skip to content
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
17 changes: 12 additions & 5 deletions testsupport/cleanup/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,21 @@ type AwaitilityInt interface {

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

func (c *cleanManager) addCleanTasks(t *testing.T, cl client.Client, objects ...client.Object) {
func AddCleanTasksWithTimeout(t *testing.T, cl client.Client, timeout time.Duration, objects ...client.Object) {
cleaning.addCleanTasks(t, cl, timeout, objects...)
}

func (c *cleanManager) addCleanTasks(t *testing.T, cl client.Client, timeout time.Duration, objects ...client.Object) {
c.Lock()
defer c.Unlock()
for _, obj := range objects {
if len(c.cleanTasks[t]) == 0 {
t.Cleanup(c.clean(t))
}
c.cleanTasks[t] = append(c.cleanTasks[t], newCleanTask(t, cl, obj))
c.cleanTasks[t] = append(c.cleanTasks[t], newCleanTask(t, cl, obj, timeout))
}
}

Expand Down Expand Up @@ -94,16 +98,19 @@ type cleanTask struct {
objToClean client.Object
client client.Client
t *testing.T
timeout time.Duration
}

func (c *cleanTask) clean() {
c.Do(c.cleanObject)
}
func newCleanTask(t *testing.T, cl client.Client, obj client.Object) *cleanTask {

func newCleanTask(t *testing.T, cl client.Client, obj client.Object, timeout time.Duration) *cleanTask {
return &cleanTask{
t: t,
client: cl,
objToClean: obj,
timeout: timeout,
}
}

Expand Down Expand Up @@ -141,7 +148,7 @@ func (c *cleanTask) cleanObject() {

// wait until deletion is done
c.t.Logf("waiting until %s: %s is completely deleted", kind, objToClean.GetName())
err = wait.PollUntilContextTimeout(context.TODO(), defaultRetryInterval, defaultTimeout, true, func(ctx context.Context) (done bool, err error) {
err = wait.PollUntilContextTimeout(context.TODO(), defaultRetryInterval, c.timeout, true, func(ctx context.Context) (done bool, err error) {
if err := c.client.Get(context.TODO(), test.NamespacedName(objToClean.GetNamespace(), objToClean.GetName()), objToClean); err != nil {
if errors.IsNotFound(err) {
// if the object was UserSignup, then let's check that the MUR is deleted as well
Expand Down
4 changes: 3 additions & 1 deletion testsupport/tiers/tier_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"testing"
"time"

toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
"github.com/codeready-toolchain/toolchain-common/pkg/configuration"
Expand Down Expand Up @@ -135,7 +136,8 @@ func CreateCustomNSTemplateTier(t *testing.T, hostAwait *wait.HostAwaitility, na
err := modify(hostAwait, tier)
require.NoError(t, err)
}
err := hostAwait.CreateWithCleanup(t, tier.NSTemplateTier)
// NSTemplateTier can take a long time to delete because they wait for all their spaces to be deleted first...
err := hostAwait.CreateWithCleanupTimeout(t, tier.NSTemplateTier, 2*time.Minute)
require.NoError(t, err)
newTTier, err := hostAwait.WaitForNSTemplateTier(t, tier.Name,
wait.HasStatusTierTemplateRevisions(GetTemplateRefs(t, hostAwait, tier.Name).Flatten()))
Expand Down
8 changes: 8 additions & 0 deletions testsupport/wait/awaitility.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,14 @@ func (a *Awaitility) CreateWithCleanup(t *testing.T, obj client.Object, opts ...
return nil
}

func (a *Awaitility) CreateWithCleanupTimeout(t *testing.T, obj client.Object, timeout time.Duration, opts ...client.CreateOption) error {
if err := a.Client.Create(context.TODO(), obj, opts...); err != nil {
return err
}
cleanup.AddCleanTasksWithTimeout(t, a.GetClient(), timeout, obj)
return nil
}

// Creates a copy of the object specified using the `from` parameter. The created copy is named using the `to` parameter and is cleaned up
// after the test. The object can be modified using the optionally supplied modifiers before it is created. The `object` is an "output parameter"
// that will contain the object as it was created in the cluster.
Expand Down
Loading