Skip to content

Commit

Permalink
SLO tests: make less flaky. (#1943)
Browse files Browse the repository at this point in the history
* Runs SLO tests serially, making plan interference less likely.
* Adds a short delay after an out-of-band SLO delete, to allow
  background workers to clean up the resources. This should reduce
  flakiness when planning after the deletion.
  • Loading branch information
joeblubaugh authored Dec 6, 2024
1 parent 0cb6577 commit ff6465f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/resources/slo/data_source_slo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestAccDataSourceSlo(t *testing.T) {
randomName := acctest.RandomWithPrefix("SLO Terraform Testing")

var slo slo.SloV00Slo
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
CheckDestroy: testAccSloCheckDestroy(&slo),
Steps: []resource.TestStep{
Expand Down
9 changes: 6 additions & 3 deletions internal/resources/slo/resource_slo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"regexp"
"strings"
"testing"
"time"

"github.com/grafana/slo-openapi-client/go/slo"
"github.com/grafana/terraform-provider-grafana/v3/internal/common"
Expand All @@ -23,7 +24,7 @@ func TestAccResourceSlo(t *testing.T) {
randomName := acctest.RandomWithPrefix("SLO Terraform Testing")

var slo slo.SloV00Slo
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
// Implicitly tests destroy
CheckDestroy: testAccSloCheckDestroy(&slo),
Expand Down Expand Up @@ -146,7 +147,7 @@ func TestAccSLO_recreate(t *testing.T) {
config := testutils.TestAccExampleWithReplace(t, "resources/grafana_slo/resource.tf", map[string]string{
"Terraform Testing": randomName,
})
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,

// Implicitly tests destroy
Expand Down Expand Up @@ -175,6 +176,8 @@ func TestAccSLO_recreate(t *testing.T) {
req := client.DefaultAPI.V1SloIdDelete(context.Background(), slo.Uuid)
_, err := req.Execute()
require.NoError(t, err)
// A short delay while background tasks clean up the SLO. After this, the plan should be non-empty again.
time.Sleep(5 * time.Second)
},
Config: config,
PlanOnly: true,
Expand Down Expand Up @@ -395,7 +398,7 @@ resource "grafana_slo" "no_alert" {
func TestAccResourceInvalidSlo(t *testing.T) {
testutils.CheckCloudInstanceTestsEnabled(t)

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Expand Down

0 comments on commit ff6465f

Please sign in to comment.