Skip to content

Commit

Permalink
tests: Do not wait the retry interval during acceptance tests (scalew…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeansebastienh authored May 11, 2021
1 parent 6863c77 commit b26ec38
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 52 deletions.
5 changes: 5 additions & 0 deletions scaleway/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions scaleway/helpers_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions scaleway/helpers_iot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions scaleway/helpers_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions scaleway/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"regexp"
"strings"
"testing"
"time"

"github.com/dnaeon/go-vcr/cassette"
"github.com/dnaeon/go-vcr/recorder"
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion scaleway/resource_apple_silicon_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 16 additions & 12 deletions scaleway/resource_baremetal_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions scaleway/resource_instance_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions scaleway/resource_instance_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 8 additions & 6 deletions scaleway/resource_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
28 changes: 16 additions & 12 deletions scaleway/resource_rdb_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit b26ec38

Please sign in to comment.