Skip to content

Commit 0c09058

Browse files
committed
test(redis): harden destroy checks with RetryContext
1 parent 54a6f9b commit 0c09058

File tree

2 files changed

+436
-1163
lines changed

2 files changed

+436
-1163
lines changed

internal/services/redis/cluster_test.go

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package redis_test
22

33
import (
4+
"context"
45
"crypto/x509"
56
"encoding/pem"
67
"errors"
78
"fmt"
89
"testing"
10+
"time"
911

12+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1013
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1114
"github.com/hashicorp/terraform-plugin-testing/terraform"
1215
redisSDK "github.com/scaleway/scaleway-sdk-go/api/redis/v1"
@@ -760,31 +763,36 @@ func TestAccCluster_MigrateToHAMode(t *testing.T) {
760763

761764
func isClusterDestroyed(tt *acctest.TestTools) resource.TestCheckFunc {
762765
return func(state *terraform.State) error {
763-
for _, rs := range state.RootModule().Resources {
764-
if rs.Type != "scaleway_redis_cluster" {
765-
continue
766-
}
767-
768-
redisAPI, zone, ID, err := redis.NewAPIWithZoneAndID(tt.Meta, rs.Primary.ID)
769-
if err != nil {
770-
return err
771-
}
766+
ctx := context.Background()
772767

773-
_, err = redisAPI.GetCluster(&redisSDK.GetClusterRequest{
774-
ClusterID: ID,
775-
Zone: zone,
776-
})
768+
return retry.RetryContext(ctx, 3*time.Minute, func() *retry.RetryError {
769+
for _, rs := range state.RootModule().Resources {
770+
if rs.Type != "scaleway_redis_cluster" {
771+
continue
772+
}
777773

778-
if err == nil {
779-
return fmt.Errorf("cluster (%s) still exists", rs.Primary.ID)
780-
}
774+
api, zone, id, err := redis.NewAPIWithZoneAndID(tt.Meta, rs.Primary.ID)
775+
if err != nil {
776+
return retry.NonRetryableError(err)
777+
}
781778

782-
if !httperrors.Is404(err) {
783-
return err
779+
_, err = api.GetCluster(&redisSDK.GetClusterRequest{
780+
ClusterID: id,
781+
Zone: zone,
782+
})
783+
784+
switch {
785+
case err == nil:
786+
return retry.RetryableError(fmt.Errorf("redis cluster (%s) still exists", rs.Primary.ID))
787+
case httperrors.Is404(err):
788+
continue
789+
default:
790+
return retry.NonRetryableError(err)
791+
}
784792
}
785-
}
786793

787-
return nil
794+
return nil
795+
})
788796
}
789797
}
790798

0 commit comments

Comments
 (0)