Skip to content

Commit

Permalink
chore: add retries on flaky acc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wbeuil committed Feb 3, 2022
1 parent 1fc2e35 commit f801244
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/resource/aws/aws_eip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ func TestAcc_Aws_Eip(t *testing.T) {
Env: map[string]string{
"AWS_REGION": "us-east-1",
},
// New resources are not visible immediately through AWS API after an apply operation
// (e.g. error attaching EC2 Internet Gateway)
// Logic below retries driftctl scan using a back-off strategy of retrying 'n' times
// and doubling the amount of time waited after each one.
ShouldRetry: func(result *test.ScanResult, retryDuration time.Duration, retryCount uint8) bool {
if result.IsSync() || retryDuration > 10*time.Minute {
return false
}
time.Sleep((2 * time.Duration(retryCount)) * time.Minute)
return true
},
Check: func(result *test.ScanResult, stdout string, err error) {
if err != nil {
t.Fatal(err)
Expand Down
11 changes: 11 additions & 0 deletions pkg/resource/aws/aws_internet_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ func TestAcc_Aws_InternetGateway(t *testing.T) {
Env: map[string]string{
"AWS_REGION": "us-east-1",
},
// New resources are not visible immediately through AWS API after an apply operation
// (e.g. InvalidVpcID.NotFound)
// Logic below retries driftctl scan using a back-off strategy of retrying 'n' times
// and doubling the amount of time waited after each one.
ShouldRetry: func(result *test.ScanResult, retryDuration time.Duration, retryCount uint8) bool {
if result.IsSync() || retryDuration > 10*time.Minute {
return false
}
time.Sleep((2 * time.Duration(retryCount)) * time.Minute)
return true
},
Check: func(result *test.ScanResult, stdout string, err error) {
if err != nil {
t.Fatal(err)
Expand Down
12 changes: 12 additions & 0 deletions pkg/resource/aws/aws_network_acl_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/snyk/driftctl/test"
"github.com/snyk/driftctl/test/acceptance"
Expand Down Expand Up @@ -41,6 +42,17 @@ func TestAcc_Aws_NetworkAcl_NonDeep(t *testing.T) {
Env: map[string]string{
"AWS_REGION": "us-east-1",
},
// New resources are not visible immediately through AWS API after an apply operation
// (e.g. InvalidNetworkAclID.NotFound)
// Logic below retries driftctl scan using a back-off strategy of retrying 'n' times
// and doubling the amount of time waited after each one.
ShouldRetry: func(result *test.ScanResult, retryDuration time.Duration, retryCount uint8) bool {
if result.IsSync() || retryDuration > 10*time.Minute {
return false
}
time.Sleep((2 * time.Duration(retryCount)) * time.Minute)
return true
},
Check: func(result *test.ScanResult, stdout string, err error) {
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit f801244

Please sign in to comment.