Skip to content

Commit b9752e4

Browse files
authored
chore: add support for retry delay to reduce the amount of logs in the CI (#3360)
* chore: add support for retry delay to reduce the amount of logs in the CI * fix lint
1 parent c4455c2 commit b9752e4

File tree

7 files changed

+43
-10
lines changed

7 files changed

+43
-10
lines changed

.github/workflows/nightly.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ jobs:
7474
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
7575
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
7676
SCW_DEFAULT_PROJECT_ID: ${{ secrets.SCW_DEFAULT_PROJECT_ID }}
77+
# Having long retry intervals will ensure that we have few requests done while waiting on call to complete (using time.ParseDuration)
78+
TF_RETRY_DELAY: 30s
7779
- name: Ping on failure
7880
if: ${{ failure() }}
7981
run: |

internal/acctest/acctest.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
11+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/env"
1112
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
1213
"github.com/scaleway/terraform-provider-scaleway/v2/internal/provider"
1314
"github.com/scaleway/terraform-provider-scaleway/v2/internal/transport"
@@ -46,8 +47,18 @@ func NewTestTools(t *testing.T) *TestTools {
4647
require.NoError(t, err)
4748

4849
if !*UpdateCassettes {
50+
// If no recording is happening, the delay to retry to interactions should be 0
4951
tmp := 0 * time.Second
5052
transport.DefaultWaitRetryInterval = &tmp
53+
} else if os.Getenv(env.RetryDelay) != "" {
54+
// Overriding the delay interval is helpful to reduce the amount of requests performed while waiting for a ressource to be available
55+
tmp, err := time.ParseDuration(os.Getenv(env.RetryDelay))
56+
if err != nil {
57+
t.Fatal(err)
58+
}
59+
60+
t.Logf("delay retry set to: %v", tmp)
61+
transport.DefaultWaitRetryInterval = &tmp
5162
}
5263

5364
return &TestTools{

internal/acctest/domain.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"regexp"
77

8+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/env"
89
"github.com/scaleway/terraform-provider-scaleway/v2/internal/logging"
910
)
1011

@@ -22,11 +23,11 @@ var (
2223
)
2324

2425
func init() {
25-
testDomainPtr := flag.String("test-domain", os.Getenv("TF_TEST_DOMAIN"), "Test domain")
26+
testDomainPtr := flag.String("test-domain", os.Getenv(env.TestDomain), "Test domain")
2627
if testDomainPtr != nil && *testDomainPtr != "" {
2728
TestDomain = *testDomainPtr
2829
} else {
29-
logging.L.Infof("environment variable TF_TEST_DOMAIN is required")
30+
logging.L.Infof("environment variable %s is required", env.TestDomain)
3031

3132
return
3233
}
@@ -43,18 +44,18 @@ func init() {
4344
}
4445

4546
if isReserved {
46-
logging.L.Warningf("TF_TEST_DOMAIN cannot be a Scaleway required domain. Please use another one.")
47+
logging.L.Warningf("%s cannot be a Scaleway required domain. Please use another one.", env.TestDomain)
4748

4849
return
4950
}
5051

5152
logging.L.Infof("start domain record test with domain: %s", TestDomain)
5253

53-
testDomainZonePtr := flag.String("test-domain-zone", os.Getenv("TF_TEST_DOMAIN_ZONE"), "Test domain zone")
54+
testDomainZonePtr := flag.String("test-domain-zone", os.Getenv(env.TestDomainZone), "Test domain zone")
5455
if testDomainZonePtr != nil && *testDomainZonePtr != "" {
5556
TestDomainZone = *testDomainZonePtr
5657
} else {
57-
logging.L.Infof("environment variable TF_TEST_DOMAIN_ZONE is required")
58+
logging.L.Infof("environment variable %s is required", env.TestDomainZone)
5859

5960
return
6061
}

internal/acctest/vcr.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
"github.com/scaleway/scaleway-sdk-go/scw"
1818
"github.com/scaleway/scaleway-sdk-go/strcase"
19+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/env"
1920
"github.com/scaleway/terraform-provider-scaleway/v2/internal/logging"
2021
"github.com/scaleway/terraform-provider-scaleway/v2/internal/transport"
2122
"github.com/stretchr/testify/require"
@@ -24,7 +25,7 @@ import (
2425
)
2526

2627
// UpdateCassettes will update all cassettes of a given test
27-
var UpdateCassettes = flag.Bool("cassettes", os.Getenv("TF_UPDATE_CASSETTES") == "true", "Record Cassettes")
28+
var UpdateCassettes = flag.Bool("cassettes", os.Getenv(env.UpdateCassettes) == "true", "Record Cassettes")
2829

2930
// SensitiveFields is a map with keys listing fields that should be anonymized
3031
// value will be set in place of its old value

internal/env/env.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Package env contains a list of environment variables used to modify the behaviour of the provider
2+
package env
3+
4+
const (
5+
// RetryDelay is a duration string (parsed with time.ParseDuration) will change how long the SDK will wait between to attempts
6+
RetryDelay = "TF_RETRY_DELAY"
7+
// UpdateCassettes if set to "true" will trigger the cassettes to be recorded
8+
UpdateCassettes = "TF_UPDATE_CASSETTES"
9+
// TestDomain is the DNS domain used during our tests
10+
TestDomain = "TF_TEST_DOMAIN"
11+
// TestDomainZone is the DNS zone used during our tests
12+
TestDomainZone = "TF_TEST_DOMAIN_ZONE"
13+
// AppendUserAgent is appended to the user agent of the underlying SDK go
14+
AppendUserAgent = "TF_APPEND_USER_AGENT"
15+
// AccDomainRegistration if set to "true" will trigger acceptance test for domain registration
16+
AccDomainRegistration = "TF_ACC_DOMAIN_REGISTRATION"
17+
)

internal/meta/meta.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import (
1313
"github.com/hashicorp/terraform-plugin-log/tflog"
1414
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1515
"github.com/scaleway/scaleway-sdk-go/scw"
16+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/env"
1617
"github.com/scaleway/terraform-provider-scaleway/v2/internal/transport"
1718
"github.com/scaleway/terraform-provider-scaleway/v2/version"
1819
)
1920

2021
const (
21-
appendUserAgentEnvVar = "TF_APPEND_USER_AGENT"
2222
CredentialsSourceEnvironment = "Environment variable"
2323
CredentialsSourceDefault = "Default"
2424
CredentialsSourceActiveProfile = "Active Profile in config.yaml"
@@ -197,7 +197,7 @@ type Config struct {
197197
func customizeUserAgent(providerVersion string, terraformVersion string) string {
198198
userAgent := fmt.Sprintf("terraform-provider/%s terraform/%s", providerVersion, terraformVersion)
199199

200-
if appendUserAgent := os.Getenv(appendUserAgentEnvVar); appendUserAgent != "" {
200+
if appendUserAgent := os.Getenv(env.AppendUserAgent); appendUserAgent != "" {
201201
userAgent += " " + appendUserAgent
202202
}
203203

internal/services/domain/registration_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/hashicorp/terraform-plugin-testing/terraform"
1111
domainSDK "github.com/scaleway/scaleway-sdk-go/api/domain/v2beta1"
1212
"github.com/scaleway/terraform-provider-scaleway/v2/internal/acctest"
13+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/env"
1314
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
1415
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/domain"
1516
)
@@ -268,9 +269,9 @@ func testAccCheckDomainDestroy(tt *acctest.TestTools) resource.TestCheckFunc {
268269
// If `TF_UPDATE_CASSETTES=true`, the test is **only executed if `TF_ACC_DOMAIN_REGISTRATION=true`**.
269270
// Otherwise, the test is skipped to prevent unintended domain reservations.
270271
func shouldBeSkipped() bool {
271-
if os.Getenv("TF_UPDATE_CASSETTES") == "false" {
272+
if os.Getenv(env.UpdateCassettes) == "false" {
272273
return false
273274
}
274275

275-
return os.Getenv("TF_ACC_DOMAIN_REGISTRATION") != "true"
276+
return os.Getenv(env.AccDomainRegistration) != "true"
276277
}

0 commit comments

Comments
 (0)