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

chore: Adds sleep in tests to avoid out of capacity errors #2674

Merged
merged 7 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestMigAdvancedCluster_replicaSetAWSProviderUpdate(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasic(t) },
PreCheck: mig.PreCheckBasicSleep(t),
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestMigAdvancedCluster_partialAdvancedConf(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: mig.PreCheckBasicSleep(t),
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestAccClusterAdvancedCluster_basicTenant(t *testing.T) {
clusterNameUpdated = acc.RandomClusterName()
)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -64,7 +64,7 @@ func replicaSetAWSProviderTestCase(t *testing.T) resource.TestCase {
)

return resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestAccClusterAdvancedCluster_unpausedToPaused(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestAccClusterAdvancedCluster_pausedToUnpaused(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestAccClusterAdvancedCluster_advancedConfig(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -301,7 +301,7 @@ func TestAccClusterAdvancedCluster_advancedConfig_MongoDBVersion5(t *testing.T)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -342,7 +342,7 @@ func TestAccClusterAdvancedCluster_defaultWrite(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -374,7 +374,7 @@ func TestAccClusterAdvancedClusterConfig_replicationSpecsAutoScaling(t *testing.
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -417,7 +417,7 @@ func TestAccClusterAdvancedClusterConfig_replicationSpecsAnalyticsAutoScaling(t
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -530,7 +530,7 @@ func TestAccClusterAdvancedClusterConfig_selfManagedShardingIncorrectType(t *tes
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestMigBackupRSCloudBackupSnapshot_sharded(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: mig.PreCheckBasicSleep(t),
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestAccBackupRSCloudBackupSnapshot_sharded(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
Expand Down
18 changes: 9 additions & 9 deletions internal/service/cluster/resource_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func basicTestCase(tb testing.TB) *resource.TestCase {
)

return &resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(tb) },
PreCheck: acc.PreCheckBasicSleep(tb),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -101,7 +101,7 @@ func partialAdvancedConfTestCase(tb testing.TB) *resource.TestCase {
)

return &resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(tb) },
PreCheck: acc.PreCheckBasicSleep(tb),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestAccCluster_basic_DefaultWriteRead_AdvancedConf(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestAccCluster_emptyAdvancedConf(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -264,7 +264,7 @@ func TestAccCluster_basicAdvancedConf(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -625,7 +625,7 @@ func TestAccCluster_AWSWithLabels(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -986,7 +986,7 @@ func TestAccCluster_withAutoScalingAWS(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -1267,7 +1267,7 @@ func TestAccCluster_basicAWS_UnpauseToPaused(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -1315,7 +1315,7 @@ func TestAccCluster_basicAWS_PausedToUnpaused(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
PreCheck: acc.PreCheckBasicSleep(t),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
Expand Down
10 changes: 10 additions & 0 deletions internal/testutil/acc/pre_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ func PreCheckBasic(tb testing.TB) {
}
}

// PreCheckBasicSleep is a helper function to call SerialSleep, see its help for more info.
// Some examples of use are when the test is calling ProjectIDExecution or GetClusterInfo.
func PreCheckBasicSleep(tb testing.TB) func() {
tb.Helper()
return func() {
PreCheckBasic(tb)
SerialSleep(tb)
}
}

// PreCheck checks common Atlas environment variables and MONGODB_ATLAS_PROJECT_ID.
// Deprecated: it should not be used as MONGODB_ATLAS_PROJECT_ID is not intended to be used in CI.
// Use PreCheckBasic instead.
Expand Down
15 changes: 13 additions & 2 deletions internal/testutil/acc/shared_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ func ProjectIDExecution(tb testing.TB) string {
sharedInfo.projectName = RandomProjectName()
tb.Logf("Creating execution project: %s\n", sharedInfo.projectName)
sharedInfo.projectID = createProject(tb, sharedInfo.projectName)
} else {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert previous PR

time.Sleep(20 * time.Second) // HELP-65223: sleep a few seconds so clusters are not created concurrently in the execution project
}

return sharedInfo.projectID
Expand Down Expand Up @@ -87,10 +85,23 @@ func ClusterNameExecution(tb testing.TB) (projectID, clusterName string) {
return sharedInfo.projectID, sharedInfo.clusterName
}

// SerialSleep waits a few seconds so clusters are not created concurrently in the execution project, see HELP-65223.
// This must be called once the test is marked as parallel, e.g. in PreCheck inside resource.ParallelTest.
func SerialSleep(tb testing.TB) {
tb.Helper()
SkipInUnitTest(tb)
require.True(tb, sharedInfo.init, "SetupSharedResources must called from TestMain test package")

sharedInfo.muSleep.Lock()
defer sharedInfo.muSleep.Unlock()
time.Sleep(10 * time.Second)
EspenAlbert marked this conversation as resolved.
Show resolved Hide resolved
}

var sharedInfo = struct {
projectID string
projectName string
clusterName string
mu sync.Mutex
muSleep sync.Mutex
init bool
}{}
10 changes: 10 additions & 0 deletions internal/testutil/mig/pre_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ func PreCheckBasic(tb testing.TB) {
acc.PreCheckBasic(tb)
}

// PreCheckBasicSleep is a helper function to call SerialSleep, see its help for more info.
// Some examples of use are when the test is calling ProjectIDExecution or GetClusterInfo.
func PreCheckBasicSleep(tb testing.TB) func() {
tb.Helper()
return func() {
PreCheckBasic(tb)
acc.SerialSleep(tb)
}
}

func PreCheck(tb testing.TB) {
tb.Helper()
checkLastVersion(tb)
Expand Down