From b26ec38d1bd5533fd3b5deffa5469042eba92ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Hedde?= Date: Tue, 11 May 2021 17:10:29 +0200 Subject: [PATCH] tests: Do not wait the retry interval during acceptance tests (#828) --- scaleway/helpers.go | 5 ++++ scaleway/helpers_instance.go | 14 +++++++----- scaleway/helpers_iot.go | 5 ++-- scaleway/helpers_k8s.go | 21 +++++++++-------- scaleway/provider_test.go | 6 +++++ scaleway/resource_apple_silicon_server.go | 2 +- scaleway/resource_baremetal_server.go | 28 +++++++++++++---------- scaleway/resource_instance_snapshot.go | 5 ++-- scaleway/resource_instance_volume.go | 6 +++-- scaleway/resource_lb.go | 14 +++++++----- scaleway/resource_rdb_instance.go | 28 +++++++++++++---------- 11 files changed, 82 insertions(+), 52 deletions(-) diff --git a/scaleway/helpers.go b/scaleway/helpers.go index 38fb19f9cd..5768ec133e 100644 --- a/scaleway/helpers.go +++ b/scaleway/helpers.go @@ -17,6 +17,11 @@ import ( "golang.org/x/xerrors" ) +var ( + // DefaultWaitRetryInterval is used to set the retry interval to 0 during acceptance tests + DefaultWaitRetryInterval *time.Duration +) + // RegionalID represents an ID that is linked with a region, eg fr-par/11111111-1111-1111-1111-111111111111 type RegionalID struct { ID string diff --git a/scaleway/helpers_instance.go b/scaleway/helpers_instance.go index fa885814e3..ce452633be 100644 --- a/scaleway/helpers_instance.go +++ b/scaleway/helpers_instance.go @@ -139,8 +139,9 @@ func reachState(ctx context.Context, instanceAPI *instance.API, zone scw.Zone, s for _, volume := range response.Server.Volumes { if volume.State != instance.VolumeStateAvailable { _, err = instanceAPI.WaitForVolume(&instance.WaitForVolumeRequest{ - Zone: zone, - VolumeID: volume.ID, + Zone: zone, + VolumeID: volume.ID, + RetryInterval: DefaultWaitRetryInterval, }) if err != nil { return err @@ -150,10 +151,11 @@ func reachState(ctx context.Context, instanceAPI *instance.API, zone scw.Zone, s for _, a := range actions { err = instanceAPI.ServerActionAndWait(&instance.ServerActionAndWaitRequest{ - ServerID: serverID, - Action: a, - Zone: zone, - Timeout: scw.TimeDurationPtr(defaultInstanceServerWaitTimeout), + ServerID: serverID, + Action: a, + Zone: zone, + Timeout: scw.TimeDurationPtr(defaultInstanceServerWaitTimeout), + RetryInterval: DefaultWaitRetryInterval, }) if err != nil { return err diff --git a/scaleway/helpers_iot.go b/scaleway/helpers_iot.go index 4cca0cf67d..4837df4b97 100644 --- a/scaleway/helpers_iot.go +++ b/scaleway/helpers_iot.go @@ -27,8 +27,9 @@ func iotAPIWithRegionAndID(m interface{}, id string) (*iot.API, scw.Region, stri func waitIotHub(iotAPI *iot.API, region scw.Region, hubID string, desiredStates ...iot.HubStatus) error { hub, err := iotAPI.WaitForHub(&iot.WaitForHubRequest{ - HubID: hubID, - Region: region, + HubID: hubID, + Region: region, + RetryInterval: DefaultWaitRetryInterval, }) if err != nil { return err diff --git a/scaleway/helpers_k8s.go b/scaleway/helpers_k8s.go index 20c450c67a..caa6f262af 100644 --- a/scaleway/helpers_k8s.go +++ b/scaleway/helpers_k8s.go @@ -104,9 +104,10 @@ func k8sGetLatestVersionFromMinor(ctx context.Context, k8sAPI *k8s.API, region s func waitK8SCluster(ctx context.Context, k8sAPI *k8s.API, region scw.Region, clusterID string, desiredStates ...k8s.ClusterStatus) error { cluster, err := k8sAPI.WaitForCluster(&k8s.WaitForClusterRequest{ - ClusterID: clusterID, - Region: region, - Timeout: scw.TimeDurationPtr(K8SClusterWaitForPoolRequiredTimeout), + ClusterID: clusterID, + Region: region, + Timeout: scw.TimeDurationPtr(K8SClusterWaitForPoolRequiredTimeout), + RetryInterval: DefaultWaitRetryInterval, }, scw.WithContext(ctx)) if err != nil { return err @@ -123,9 +124,10 @@ func waitK8SCluster(ctx context.Context, k8sAPI *k8s.API, region scw.Region, clu func waitK8SClusterDeleted(ctx context.Context, k8sAPI *k8s.API, region scw.Region, clusterID string) error { cluster, err := k8sAPI.WaitForCluster(&k8s.WaitForClusterRequest{ - ClusterID: clusterID, - Region: region, - Timeout: scw.TimeDurationPtr(K8SClusterWaitForDeletedTimeout), + ClusterID: clusterID, + Region: region, + Timeout: scw.TimeDurationPtr(K8SClusterWaitForDeletedTimeout), + RetryInterval: DefaultWaitRetryInterval, }, scw.WithContext(ctx)) if err != nil { if is404Error(err) { @@ -139,9 +141,10 @@ func waitK8SClusterDeleted(ctx context.Context, k8sAPI *k8s.API, region scw.Regi func waitK8SPoolReady(ctx context.Context, k8sAPI *k8s.API, region scw.Region, poolID string) error { pool, err := k8sAPI.WaitForPool(&k8s.WaitForPoolRequest{ - PoolID: poolID, - Region: region, - Timeout: scw.TimeDurationPtr(K8SPoolWaitForReadyTimeout), + PoolID: poolID, + Region: region, + Timeout: scw.TimeDurationPtr(K8SPoolWaitForReadyTimeout), + RetryInterval: DefaultWaitRetryInterval, }, scw.WithContext(ctx)) if err != nil { diff --git a/scaleway/provider_test.go b/scaleway/provider_test.go index 1196e508a4..7a0940c340 100644 --- a/scaleway/provider_test.go +++ b/scaleway/provider_test.go @@ -9,6 +9,7 @@ import ( "regexp" "strings" "testing" + "time" "github.com/dnaeon/go-vcr/cassette" "github.com/dnaeon/go-vcr/recorder" @@ -95,6 +96,11 @@ func NewTestTools(t *testing.T) *TestTools { }) require.NoError(t, err) + if !*UpdateCassettes { + tmp := 0 * time.Second + DefaultWaitRetryInterval = &tmp + } + return &TestTools{ T: t, Meta: meta, diff --git a/scaleway/resource_apple_silicon_server.go b/scaleway/resource_apple_silicon_server.go index 728d5ed930..3dd645a448 100644 --- a/scaleway/resource_apple_silicon_server.go +++ b/scaleway/resource_apple_silicon_server.go @@ -95,7 +95,7 @@ func resourceScalewayAppleSiliconServerCreate(ctx context.Context, d *schema.Res _, err = asAPI.WaitForServer(&applesilicon.WaitForServerRequest{ ServerID: res.ID, Timeout: scw.TimeDurationPtr(defaultAppleSiliconServerTimeout), - RetryInterval: nil, + RetryInterval: DefaultWaitRetryInterval, }, scw.WithContext(ctx)) if err != nil { return diag.FromErr(err) diff --git a/scaleway/resource_baremetal_server.go b/scaleway/resource_baremetal_server.go index 2346cc7660..0b4a38b67f 100644 --- a/scaleway/resource_baremetal_server.go +++ b/scaleway/resource_baremetal_server.go @@ -153,9 +153,10 @@ func resourceScalewayBaremetalServerCreate(ctx context.Context, d *schema.Resour d.SetId(newZonedID(server.Zone, server.ID).String()) _, err = baremetalAPI.WaitForServer(&baremetal.WaitForServerRequest{ - Zone: server.Zone, - ServerID: server.ID, - Timeout: scw.TimeDurationPtr(baremetalServerWaitForTimeout), + Zone: server.Zone, + ServerID: server.ID, + Timeout: scw.TimeDurationPtr(baremetalServerWaitForTimeout), + RetryInterval: DefaultWaitRetryInterval, }) if err != nil { return diag.FromErr(err) @@ -173,9 +174,10 @@ func resourceScalewayBaremetalServerCreate(ctx context.Context, d *schema.Resour } _, err = baremetalAPI.WaitForServerInstall(&baremetal.WaitForServerInstallRequest{ - Zone: server.Zone, - ServerID: server.ID, - Timeout: scw.TimeDurationPtr(baremetalServerWaitForTimeout), + Zone: server.Zone, + ServerID: server.ID, + Timeout: scw.TimeDurationPtr(baremetalServerWaitForTimeout), + RetryInterval: DefaultWaitRetryInterval, }) if err != nil { return diag.FromErr(err) @@ -259,9 +261,10 @@ func resourceScalewayBaremetalServerUpdate(ctx context.Context, d *schema.Resour } _, err = baremetalAPI.WaitForServerInstall(&baremetal.WaitForServerInstallRequest{ - Zone: server.Zone, - ServerID: server.ID, - Timeout: scw.TimeDurationPtr(baremetalServerWaitForTimeout), + Zone: server.Zone, + ServerID: server.ID, + Timeout: scw.TimeDurationPtr(baremetalServerWaitForTimeout), + RetryInterval: DefaultWaitRetryInterval, }) if err != nil { return diag.FromErr(err) @@ -290,9 +293,10 @@ func resourceScalewayBaremetalServerDelete(ctx context.Context, d *schema.Resour } _, err = baremetalAPI.WaitForServer(&baremetal.WaitForServerRequest{ - Zone: server.Zone, - ServerID: server.ID, - Timeout: scw.TimeDurationPtr(baremetalServerWaitForTimeout), + Zone: server.Zone, + ServerID: server.ID, + Timeout: scw.TimeDurationPtr(baremetalServerWaitForTimeout), + RetryInterval: DefaultWaitRetryInterval, }) if err != nil && !is404Error(err) { diff --git a/scaleway/resource_instance_snapshot.go b/scaleway/resource_instance_snapshot.go index 10dcf29a01..57d515b3bd 100644 --- a/scaleway/resource_instance_snapshot.go +++ b/scaleway/resource_instance_snapshot.go @@ -136,8 +136,9 @@ func resourceScalewayInstanceSnapshotDelete(ctx context.Context, d *schema.Resou } _, err = instanceAPI.WaitForSnapshot(&instance.WaitForSnapshotRequest{ - SnapshotID: id, - Zone: zone, + SnapshotID: id, + Zone: zone, + RetryInterval: DefaultWaitRetryInterval, }) if err != nil { return diag.FromErr(err) diff --git a/scaleway/resource_instance_volume.go b/scaleway/resource_instance_volume.go index 1d8c16481d..b1637689f9 100644 --- a/scaleway/resource_instance_volume.go +++ b/scaleway/resource_instance_volume.go @@ -172,8 +172,10 @@ func resourceScalewayInstanceVolumeUpdate(ctx context.Context, d *schema.Resourc return diag.FromErr(fmt.Errorf("block volumes cannot be resized down")) } _, err := instanceAPI.WaitForVolume(&instance.WaitForVolumeRequest{ - VolumeID: id, - Zone: zone}, scw.WithContext(ctx)) + VolumeID: id, + Zone: zone, + RetryInterval: DefaultWaitRetryInterval, + }, scw.WithContext(ctx)) if err != nil { return diag.FromErr(err) } diff --git a/scaleway/resource_lb.go b/scaleway/resource_lb.go index b22c6db0f8..6876bdd166 100644 --- a/scaleway/resource_lb.go +++ b/scaleway/resource_lb.go @@ -91,9 +91,10 @@ func resourceScalewayLbCreate(ctx context.Context, d *schema.ResourceData, meta d.SetId(newRegionalIDString(region, res.ID)) _, err = lbAPI.WaitForLb(&lb.WaitForLBRequest{ - Region: region, - LBID: res.ID, - Timeout: scw.TimeDurationPtr(defaultInstanceServerWaitTimeout), + Region: region, + LBID: res.ID, + Timeout: scw.TimeDurationPtr(defaultInstanceServerWaitTimeout), + RetryInterval: DefaultWaitRetryInterval, }, scw.WithContext(ctx)) if err != nil { return diag.FromErr(err) @@ -174,9 +175,10 @@ func resourceScalewayLbDelete(ctx context.Context, d *schema.ResourceData, meta } _, err = lbAPI.WaitForLb(&lb.WaitForLBRequest{ - LBID: ID, - Region: region, - Timeout: scw.TimeDurationPtr(LbWaitForTimeout), + LBID: ID, + Region: region, + Timeout: scw.TimeDurationPtr(LbWaitForTimeout), + RetryInterval: DefaultWaitRetryInterval, }, scw.WithContext(ctx)) if err != nil && !is404Error(err) { diff --git a/scaleway/resource_rdb_instance.go b/scaleway/resource_rdb_instance.go index 7307519866..194191f30d 100644 --- a/scaleway/resource_rdb_instance.go +++ b/scaleway/resource_rdb_instance.go @@ -185,9 +185,10 @@ func resourceScalewayRdbInstanceCreate(ctx context.Context, d *schema.ResourceDa d.SetId(newRegionalIDString(region, res.ID)) _, err = rdbAPI.WaitForInstance(&rdb.WaitForInstanceRequest{ - Region: region, - InstanceID: res.ID, - Timeout: scw.TimeDurationPtr(defaultInstanceServerWaitTimeout), + Region: region, + InstanceID: res.ID, + Timeout: scw.TimeDurationPtr(defaultInstanceServerWaitTimeout), + RetryInterval: DefaultWaitRetryInterval, }, scw.WithContext(ctx)) if err != nil { return diag.FromErr(err) @@ -383,9 +384,10 @@ func resourceScalewayRdbInstanceUpdate(ctx context.Context, d *schema.ResourceDa } _, err = rdbAPI.WaitForInstance(&rdb.WaitForInstanceRequest{ - Region: region, - InstanceID: ID, - Timeout: scw.TimeDurationPtr(defaultInstanceServerWaitTimeout * 3), // upgrade takes some time + Region: region, + InstanceID: ID, + Timeout: scw.TimeDurationPtr(defaultInstanceServerWaitTimeout * 3), // upgrade takes some time + RetryInterval: DefaultWaitRetryInterval, }, scw.WithContext(ctx)) if err != nil { return diag.FromErr(err) @@ -420,9 +422,10 @@ func resourceScalewayRdbInstanceDelete(ctx context.Context, d *schema.ResourceDa // We first wait in case the instance is in a transient state _, err = rdbAPI.WaitForInstance(&rdb.WaitForInstanceRequest{ - InstanceID: ID, - Region: region, - Timeout: scw.TimeDurationPtr(LbWaitForTimeout), + InstanceID: ID, + Region: region, + Timeout: scw.TimeDurationPtr(LbWaitForTimeout), + RetryInterval: DefaultWaitRetryInterval, }, scw.WithContext(ctx)) if err != nil && !is404Error(err) { @@ -439,9 +442,10 @@ func resourceScalewayRdbInstanceDelete(ctx context.Context, d *schema.ResourceDa } _, err = rdbAPI.WaitForInstance(&rdb.WaitForInstanceRequest{ - InstanceID: ID, - Region: region, - Timeout: scw.TimeDurationPtr(LbWaitForTimeout), + InstanceID: ID, + Region: region, + Timeout: scw.TimeDurationPtr(LbWaitForTimeout), + RetryInterval: DefaultWaitRetryInterval, }, scw.WithContext(ctx)) if err != nil && !is404Error(err) {