Skip to content

Commit ff6465f

Browse files
authored
SLO tests: make less flaky. (#1943)
* 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.
1 parent 0cb6577 commit ff6465f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

internal/resources/slo/data_source_slo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestAccDataSourceSlo(t *testing.T) {
1515
randomName := acctest.RandomWithPrefix("SLO Terraform Testing")
1616

1717
var slo slo.SloV00Slo
18-
resource.ParallelTest(t, resource.TestCase{
18+
resource.Test(t, resource.TestCase{
1919
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
2020
CheckDestroy: testAccSloCheckDestroy(&slo),
2121
Steps: []resource.TestStep{

internal/resources/slo/resource_slo_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"regexp"
88
"strings"
99
"testing"
10+
"time"
1011

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

2526
var slo slo.SloV00Slo
26-
resource.ParallelTest(t, resource.TestCase{
27+
resource.Test(t, resource.TestCase{
2728
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
2829
// Implicitly tests destroy
2930
CheckDestroy: testAccSloCheckDestroy(&slo),
@@ -146,7 +147,7 @@ func TestAccSLO_recreate(t *testing.T) {
146147
config := testutils.TestAccExampleWithReplace(t, "resources/grafana_slo/resource.tf", map[string]string{
147148
"Terraform Testing": randomName,
148149
})
149-
resource.ParallelTest(t, resource.TestCase{
150+
resource.Test(t, resource.TestCase{
150151
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
151152

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

398-
resource.ParallelTest(t, resource.TestCase{
401+
resource.Test(t, resource.TestCase{
399402
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
400403
Steps: []resource.TestStep{
401404
{

0 commit comments

Comments
 (0)