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

tests/r/dms_replication_instance: Add sweeper concurrency #18623

Merged
merged 1 commit into from
Apr 7, 2021
Merged
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
58 changes: 23 additions & 35 deletions aws/resource_aws_dms_replication_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"log"
"sort"
"testing"
"time"

"github.com/aws/aws-sdk-go/aws"
dms "github.com/aws/aws-sdk-go/service/databasemigrationservice"
multierror "github.com/hashicorp/go-multierror"
gversion "github.com/hashicorp/go-version"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -24,57 +24,45 @@ func init() {

func testSweepDmsReplicationInstances(region string) error {
client, err := sharedClientForRegion(region)

if err != nil {
return fmt.Errorf("error getting client: %s", err)
}

conn := client.(*AWSClient).dmsconn
sweepResources := make([]*testSweepResource, 0)
var errs *multierror.Error

err = conn.DescribeReplicationInstancesPages(&dms.DescribeReplicationInstancesInput{}, func(page *dms.DescribeReplicationInstancesOutput, lastPage bool) bool {
for _, instance := range page.ReplicationInstances {
arn := aws.StringValue(instance.ReplicationInstanceArn)
input := &dms.DeleteReplicationInstanceInput{
ReplicationInstanceArn: instance.ReplicationInstanceArn,
}

log.Printf("[INFO] Deleting DMS Replication Instance: %s", arn)
_, err := conn.DeleteReplicationInstance(input)

if isAWSErr(err, dms.ErrCodeResourceNotFoundFault, "") {
continue
}

if err != nil {
log.Printf("[ERROR] Error deleting DMS Replication Instance (%s): %s", arn, err)
continue
}

stateConf := &resource.StateChangeConf{
Pending: []string{"deleting"},
Target: []string{},
Refresh: resourceAwsDmsReplicationInstanceStateRefreshFunc(conn, aws.StringValue(instance.ReplicationInstanceIdentifier)),
Timeout: 30 * time.Minute,
MinTimeout: 10 * time.Second,
Delay: 30 * time.Second,
}
r := resourceAwsDmsReplicationInstance()
d := r.Data(nil)
d.Set("replication_instance_arn", instance.ReplicationInstanceArn)
d.SetId(aws.StringValue(instance.ReplicationInstanceIdentifier))

if _, err := stateConf.WaitForState(); err != nil {
log.Printf("[ERROR] Error waiting for DMS Replication Instance (%s) deletion: %s", arn, err)
}
sweepResources = append(sweepResources, NewTestSweepResource(r, d, client))
}

return !lastPage
})

if testSweepSkipSweepError(err) {
log.Printf("[WARN] Skipping DMS Replication Instance sweep for %s: %s", region, err)
return nil
if err != nil {
errs = multierror.Append(errs, fmt.Errorf("error describing DMS Replication Instances: %w", err))
}

if err != nil {
return fmt.Errorf("Error retrieving DMS Replication Instances: %s", err)
if len(sweepResources) > 0 {
// any errors didn't prevent gathering of some work, so do it
if err := testSweepResourceOrchestrator(sweepResources); err != nil {
errs = multierror.Append(errs, fmt.Errorf("error sweeping DMS Replication Instances for %s: %w", region, err))
}
}

return nil
if testSweepSkipSweepError(errs.ErrorOrNil()) {
log.Printf("[WARN] Skipping DMS Replication Instance sweep for %s: %s", region, err)
return nil
}

return errs.ErrorOrNil()
}

func TestAccAWSDmsReplicationInstance_basic(t *testing.T) {
Expand Down