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

add retry for destroy on some acceptancy tests #887

Merged
merged 3 commits into from
Aug 2, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/resource/aws/aws_eip_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws_test

import (
"testing"
"time"

"github.com/cloudskiff/driftctl/test"
"github.com/cloudskiff/driftctl/test/acceptance"
Expand All @@ -12,6 +13,10 @@ func TestAcc_Aws_EipAssociation(t *testing.T) {
TerraformVersion: "0.14.9",
Paths: []string{"./testdata/acc/aws_eip_association"},
Args: []string{"scan", "--filter", "Type=='aws_eip' || Type=='aws_eip_association'", "--tf-provider-version", "3.44.0", "--deep"},
RetryDestroy: acceptance.RetryConfig{
Attempts: 3,
Delay: 5 * time.Second,
},
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
Expand Down
5 changes: 5 additions & 0 deletions pkg/resource/aws/aws_eip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws_test

import (
"testing"
"time"

"github.com/cloudskiff/driftctl/test"
"github.com/cloudskiff/driftctl/test/acceptance"
Expand All @@ -12,6 +13,10 @@ func TestAcc_Aws_Eip(t *testing.T) {
TerraformVersion: "0.14.9",
Paths: []string{"./testdata/acc/aws_eip"},
Args: []string{"scan", "--filter", "Type=='aws_eip' || Type=='aws_eip_association'", "--tf-provider-version", "3.44.0", "--deep"},
RetryDestroy: acceptance.RetryConfig{
Attempts: 3,
Delay: 5 * time.Second,
},
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
Expand Down
5 changes: 5 additions & 0 deletions pkg/resource/aws/aws_internet_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws_test

import (
"testing"
"time"

"github.com/cloudskiff/driftctl/test"
"github.com/cloudskiff/driftctl/test/acceptance"
Expand All @@ -12,6 +13,10 @@ func TestAcc_AwsInternetGateway(t *testing.T) {
TerraformVersion: "0.14.9",
Paths: []string{"./testdata/acc/aws_internet_gateway"},
Args: []string{"scan", "--filter", "Type=='aws_internet_gateway'", "--deep"},
RetryDestroy: acceptance.RetryConfig{
Attempts: 3,
Delay: 5 * time.Second,
},
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
Expand Down
5 changes: 5 additions & 0 deletions pkg/resource/aws/aws_route_table_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws_test

import (
"testing"
"time"

"github.com/cloudskiff/driftctl/test"
"github.com/cloudskiff/driftctl/test/acceptance"
Expand All @@ -12,6 +13,10 @@ func TestAcc_AwsRouteTableAssociation(t *testing.T) {
TerraformVersion: "0.14.9",
Paths: []string{"./testdata/acc/aws_route_table_association"},
Args: []string{"scan", "--filter", "Type=='aws_route_table_association'", "--deep"},
RetryDestroy: acceptance.RetryConfig{
Attempts: 3,
Delay: 5 * time.Second,
},
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
Expand Down
5 changes: 5 additions & 0 deletions pkg/resource/aws/aws_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws_test

import (
"testing"
"time"

"github.com/cloudskiff/driftctl/test"
"github.com/cloudskiff/driftctl/test/acceptance"
Expand All @@ -12,6 +13,10 @@ func TestAcc_AwsRoute(t *testing.T) {
TerraformVersion: "0.14.9",
Paths: []string{"./testdata/acc/aws_route"},
Args: []string{"scan", "--filter", "Type=='aws_route'", "--tf-provider-version", "3.44.0", "--deep"},
RetryDestroy: acceptance.RetryConfig{
Attempts: 3,
Delay: 5 * time.Second,
},
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
Expand Down
17 changes: 17 additions & 0 deletions test/acceptance/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/cloudskiff/driftctl/pkg/analyser"
cmderrors "github.com/cloudskiff/driftctl/pkg/cmd/errors"
"github.com/eapache/go-resiliency/retrier"
"github.com/pkg/errors"

"github.com/sirupsen/logrus"
Expand All @@ -39,6 +40,11 @@ type AccCheck struct {
Check func(result *test.ScanResult, stdout string, err error)
}

type RetryConfig struct {
Attempts uint8
Delay time.Duration
}

type AccTestCase struct {
TerraformVersion string
Paths []string
Expand All @@ -50,6 +56,7 @@ type AccTestCase struct {
originalEnv []string
tf map[string]*tfexec.Terraform
ShouldRefreshBeforeDestroy bool
RetryDestroy RetryConfig
}

func (c *AccTestCase) initTerraformExecutor() error {
Expand Down Expand Up @@ -203,6 +210,16 @@ func (c *AccTestCase) terraformApply() error {
}

func (c *AccTestCase) terraformDestroy() error {
if c.RetryDestroy.Attempts == 0 {
return c.doDestroy()
}
r := retrier.New(retrier.ConstantBackoff(int(c.RetryDestroy.Attempts), c.RetryDestroy.Delay), nil)

return r.Run(c.doDestroy)

}

func (c *AccTestCase) doDestroy() error {
if c.ShouldRefreshBeforeDestroy {
if err := c.terraformRefresh(); err != nil {
return err
Expand Down