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

feat(tests): log operation status when calling retryForever #636

Merged
merged 1 commit into from
Feb 16, 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 tests/projectvpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestProjectVPCID(t *testing.T) {

// Gets Aiven object
var kafkaAvnUpd *aiven.Service
require.NoError(t, retryForever(ctx, func() (bool, error) {
require.NoError(t, retryForever(ctx, fmt.Sprintf("migrate %s to VPC with ID %s", kafkaName, vpc2.Status.ID), func() (bool, error) {
kafkaAvnUpd, err = avnClient.Services.Get(ctx, testProject, kafkaName)
if err != nil {
return false, err
Expand Down
13 changes: 8 additions & 5 deletions tests/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

const (
retryInterval = time.Second * 5
retryInterval = time.Second * 10
createTimeout = time.Second * 15
waitRunningTimeout = time.Minute * 10
yamlBufferSize = 100
Expand Down Expand Up @@ -111,7 +111,7 @@ func (s *session) GetRunning(obj client.Object, keys ...string) error {
ctx, cancel := context.WithTimeout(s.ctx, waitRunningTimeout)
defer cancel()

return retryForever(ctx, func() (bool, error) {
return retryForever(ctx, fmt.Sprintf("verify %s is running", key), func() (bool, error) {
err := s.k8s.Get(ctx, key, obj)
if err != nil {
// The error is quite verbose
Expand Down Expand Up @@ -190,7 +190,7 @@ func (s *session) delete(o client.Object) error {

// Waits being deleted from kube
key := types.NamespacedName{Name: o.GetName(), Namespace: o.GetNamespace()}
return retryForever(s.ctx, func() (bool, error) {
return retryForever(s.ctx, fmt.Sprintf("delete %s", o.GetName()), func() (bool, error) {
err := s.k8s.Get(s.ctx, key, o)
return !isNotFound(err), nil
})
Expand All @@ -204,17 +204,20 @@ func (s *session) recover() {
}
}

func retryForever(ctx context.Context, f func() (bool, error)) (err error) {
func retryForever(ctx context.Context, operation string, f func() (bool, error)) (err error) {
retry := false
log.Printf("Starting operation: %s\n", operation)

for {
select {
case <-ctx.Done():
return fmt.Errorf("context timeout while retrying operation, error=%q", err)
return fmt.Errorf("context timeout while retrying operation: %s, error=%q", operation, err)
case <-time.After(retryInterval):
retry, err = f()
if retry {
continue
}
log.Printf("Operation %s finished\n", operation)
return err
}
}
Expand Down
Loading