Skip to content

Commit

Permalink
Fix flaky database acceptance tests. (#953)
Browse files Browse the repository at this point in the history
* Use same size for replicas as original cluster.

* Only check that version is set in Redis acceptance test.

* Use Postgres for digitalocean_database_ca test.

* Pause before running CheckDestroy in MongoDB test.

* Update size for TestAccDigitalOceanDatabaseReplica_WithVPC

* Additiona size changes.

* Pause before resizing in TestAccDigitalOceanDatabaseCluster_WithUpdate
  • Loading branch information
andrewsomething committed Feb 16, 2023
1 parent f480efc commit d1c1d2d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
9 changes: 8 additions & 1 deletion digitalocean/database/datasource_database_ca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/pem"
"fmt"
"testing"
"time"

"github.com/digitalocean/godo"
"github.com/digitalocean/terraform-provider-digitalocean/digitalocean/acceptance"
Expand All @@ -15,7 +16,7 @@ import (
func TestAccDataSourceDigitalOceanDatabaseCA(t *testing.T) {
var database godo.Database
databaseName := acceptance.RandomTestName()
databaseConfig := fmt.Sprintf(testAccCheckDigitalOceanDatabaseClusterConfigMongoDB, databaseName)
databaseConfig := fmt.Sprintf(testAccCheckDigitalOceanDatabaseClusterConfigBasic, databaseName)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
Expand All @@ -26,6 +27,12 @@ func TestAccDataSourceDigitalOceanDatabaseCA(t *testing.T) {
Config: databaseConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanDatabaseClusterExists("digitalocean_database_cluster.foobar", &database),
resource.TestCheckFunc(
func(s *terraform.State) error {
time.Sleep(30 * time.Second)
return nil
},
),
),
},
{
Expand Down
2 changes: 1 addition & 1 deletion digitalocean/database/import_database_replica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestAccDigitalOceanDatabaseReplica_importBasic(t *testing.T) {
// Requires passing both the cluster ID and replica name
ImportStateIdFunc: testAccDatabaseReplicaImportID(resourceName),
// The DO API does not return the size on read, but it is required on create
ImportStateVerifyIgnore: []string{"size"},
ImportStateVerifyIgnore: []string{"size", "uuid"},
},
// Test importing non-existent resource provides expected error.
{
Expand Down
53 changes: 30 additions & 23 deletions digitalocean/database/resource_database_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/url"
"regexp"
"testing"
"time"

"github.com/digitalocean/godo"
"github.com/digitalocean/terraform-provider-digitalocean/digitalocean/acceptance"
Expand Down Expand Up @@ -77,7 +78,16 @@ func TestAccDigitalOceanDatabaseCluster_WithUpdate(t *testing.T) {
testAccCheckDigitalOceanDatabaseClusterExists("digitalocean_database_cluster.foobar", &database),
testAccCheckDigitalOceanDatabaseClusterAttributes(&database, databaseName),
resource.TestCheckResourceAttr(
"digitalocean_database_cluster.foobar", "size", "db-s-1vcpu-1gb"),
"digitalocean_database_cluster.foobar", "size", "db-s-1vcpu-2gb"),
),
},
{
Config: fmt.Sprintf(testAccCheckDigitalOceanDatabaseClusterConfigBasic, databaseName),
Check: resource.TestCheckFunc(
func(s *terraform.State) error {
time.Sleep(30 * time.Second)
return nil
},
),
},
{
Expand All @@ -86,7 +96,7 @@ func TestAccDigitalOceanDatabaseCluster_WithUpdate(t *testing.T) {
testAccCheckDigitalOceanDatabaseClusterExists("digitalocean_database_cluster.foobar", &database),
testAccCheckDigitalOceanDatabaseClusterAttributes(&database, databaseName),
resource.TestCheckResourceAttr(
"digitalocean_database_cluster.foobar", "size", "db-s-1vcpu-2gb"),
"digitalocean_database_cluster.foobar", "size", "db-s-2vcpu-4gb"),
),
},
},
Expand Down Expand Up @@ -234,9 +244,7 @@ func TestAccDigitalOceanDatabaseCluster_RedisNoVersion(t *testing.T) {
// version. New clusters is always created with the latest version .
func TestAccDigitalOceanDatabaseCluster_oldRedisVersion(t *testing.T) {
var (
database godo.Database
client = &godo.Client{}
redisVersion string
database godo.Database
)

databaseName := acceptance.RandomTestName()
Expand All @@ -249,25 +257,14 @@ func TestAccDigitalOceanDatabaseCluster_oldRedisVersion(t *testing.T) {
{
Config: fmt.Sprintf(testAccCheckDigitalOceanDatabaseClusterRedis, databaseName, "5"),
Check: resource.ComposeTestCheckFunc(
// Fetch the Databases Options and get the current supported version of
// Redis from the response.
func(*terraform.State) error {
client = acceptance.TestAccProvider.Meta().(*config.CombinedConfig).GodoClient()
options, _, err := client.Databases.ListOptions(context.Background())
if err != nil {
t.Error("Error fetching database options")
}
redisVersion = options.RedisOptions.Versions[0]
return nil
},
testAccCheckDigitalOceanDatabaseClusterExists("digitalocean_database_cluster.foobar", &database),
testAccCheckDigitalOceanDatabaseClusterAttributes(&database, databaseName),
resource.TestCheckResourceAttr(
"digitalocean_database_cluster.foobar", "name", databaseName),
resource.TestCheckResourceAttr(
"digitalocean_database_cluster.foobar", "engine", "redis"),
resource.TestCheckResourceAttr(
"digitalocean_database_cluster.foobar", "version", redisVersion),
resource.TestCheckResourceAttrSet(
"digitalocean_database_cluster.foobar", "version"),
),
},
},
Expand Down Expand Up @@ -407,6 +404,16 @@ func TestAccDigitalOceanDatabaseCluster_MongoDBPassword(t *testing.T) {
"digitalocean_database_cluster.foobar", "private_uri"),
),
},
// Pause before running CheckDestroy
{
Config: " ",
Check: resource.TestCheckFunc(
func(s *terraform.State) error {
time.Sleep(30 * time.Second)
return nil
},
),
},
},
})
}
Expand Down Expand Up @@ -542,7 +549,7 @@ resource "digitalocean_database_cluster" "foobar" {
name = "%s"
engine = "pg"
version = "11"
size = "db-s-1vcpu-1gb"
size = "db-s-1vcpu-2gb"
region = "nyc1"
node_count = 1
tags = ["production"]
Expand All @@ -553,7 +560,7 @@ resource "digitalocean_database_cluster" "foobar" {
name = "%s"
engine = "pg"
version = "11"
size = "db-s-1vcpu-2gb"
size = "db-s-2vcpu-4gb"
region = "nyc1"
node_count = 1
tags = ["production"]
Expand All @@ -564,7 +571,7 @@ resource "digitalocean_database_cluster" "foobar" {
name = "%s"
engine = "pg"
version = "11"
size = "db-s-1vcpu-1gb"
size = "db-s-1vcpu-2gb"
region = "lon1"
node_count = 1
tags = ["production"]
Expand Down Expand Up @@ -682,7 +689,7 @@ resource "digitalocean_database_cluster" "foobar" {
name = "%s"
engine = "pg"
version = "11"
size = "db-s-1vcpu-1gb"
size = "db-s-1vcpu-2gb"
region = "nyc1"
node_count = 1
tags = ["production", "foo"]
Expand All @@ -698,7 +705,7 @@ resource "digitalocean_database_cluster" "foobar" {
name = "%s"
engine = "pg"
version = "11"
size = "db-s-1vcpu-1gb"
size = "db-s-1vcpu-2gb"
region = "nyc1"
node_count = 1
tags = ["production"]
Expand Down
6 changes: 3 additions & 3 deletions digitalocean/database/resource_database_replica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestAccDigitalOceanDatabaseReplica_Basic(t *testing.T) {
testAccCheckDigitalOceanDatabaseReplicaExists("digitalocean_database_replica.read-01", &databaseReplica),
testAccCheckDigitalOceanDatabaseReplicaAttributes(&databaseReplica, databaseReplicaName),
resource.TestCheckResourceAttr(
"digitalocean_database_replica.read-01", "size", "db-s-2vcpu-4gb"),
"digitalocean_database_replica.read-01", "size", "db-s-1vcpu-2gb"),
resource.TestCheckResourceAttr(
"digitalocean_database_replica.read-01", "region", "nyc3"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -178,7 +178,7 @@ resource "digitalocean_database_replica" "read-01" {
cluster_id = digitalocean_database_cluster.foobar.id
name = "%s"
region = "nyc3"
size = "db-s-2vcpu-4gb"
size = "db-s-1vcpu-2gb"
tags = ["staging"]
}`

Expand All @@ -189,7 +189,7 @@ resource "digitalocean_database_replica" "read-01" {
cluster_id = digitalocean_database_cluster.foobar.id
name = "%s"
region = "nyc1"
size = "db-s-2vcpu-4gb"
size = "db-s-1vcpu-2gb"
tags = ["staging"]
private_network_uuid = digitalocean_vpc.foobar.id
}`

0 comments on commit d1c1d2d

Please sign in to comment.