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

chore: increase aws redis deletion timeout #29

Merged
merged 2 commits into from
Sep 17, 2024
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
2 changes: 1 addition & 1 deletion features/300-awsredisinstance.feature
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ Feature: AwsRedisInstance feature

When resource redis is deleted
Then eventually resource authSecret does not exist
And eventually resource redis does not exist
And eventually resource redis does not exist with timeout3X
4 changes: 3 additions & 1 deletion internal/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package internal
import (
"context"
"fmt"
"os"

"github.com/cucumber/godog"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"os"
)

func Register(ctx *godog.ScenarioContext) {
Expand Down Expand Up @@ -51,6 +52,7 @@ func Register(ctx *godog.ScenarioContext) {
ctx.Step(`^resource (.*) is deleted`, resourceDeleted)
ctx.Step(`^cleanup (.*)$`, cleanup)
ctx.Step(`^resource (.*) does not exist$`, resourceDoesNotExist)
ctx.Step(`^eventually resource (.*) does not exist with (.*)$`, eventuallyResourceDoesNotExistWithOptions)
ctx.Step(`^eventually resource (.*) does not exist$`, eventuallyResourceDoesNotExist)
ctx.Step(`^there are no cloud resources$`, noCloudResources)
ctx.Step(`^module ([^ ]+)? ?is removed$`, moduleRemoved)
Expand Down
34 changes: 33 additions & 1 deletion internal/resourceDoesNotExist.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,49 @@ import (
"context"
"errors"
"fmt"
"strings"

"github.com/onsi/gomega"
)

func eventuallyResourceDoesNotExist(ctx context.Context, ref string) error {
return eventuallyResourceDoesNotExistWithOptions(ctx, ref, "")
}

func eventuallyResourceDoesNotExistWithOptions(ctx context.Context, ref string, withOpts string) error {
timeout := DefaultEventuallyTimeout

withOpts = strings.TrimSpace(withOpts)
if len(withOpts) > 0 {
opts := strings.Split(withOpts, ",")
for _, opt := range opts {
opt = strings.TrimSpace(opt)
if opt == "" {
continue
}
// ugly, but for now with just few timeout1-5X works, if you add more, try to find a better implementation.
switch opt {
case "timeout2X":
timeout = 2 * timeout
case "timeout3X":
timeout = 3 * timeout
case "timeout4X":
timeout = 4 * timeout
case "timeout5X":
timeout = 5 * timeout
default:
return fmt.Errorf("unknown option: %s", opt)
}
}
}

var errMsg string
gm := gomega.NewGomega(func(message string, callerSkip ...int) {
errMsg = message
})
ok := gm.Eventually(func(ctx context.Context, ref string) error {
return resourceDoesNotExist(ctx, ref)
}).
}, timeout).
WithArguments(ctx, ref).
Should(gomega.Succeed())
if !ok || len(errMsg) > 0 {
Expand Down
Loading