Skip to content

Commit

Permalink
kubernetes_cluster_* - fix tests with ctx deadline (hashicorp#24886)
Browse files Browse the repository at this point in the history
* add context with deadline to tests

* add context with deadline to tests

* sort imports

* add context with deadline
  • Loading branch information
catriona-m authored and rizkybiz committed Feb 21, 2024
1 parent 18a7147 commit 59f8cab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"regexp"
"strings"
"testing"
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
Expand Down Expand Up @@ -1129,6 +1130,7 @@ func (KubernetesClusterNodePoolResource) scaleNodePool(nodeCount int) acceptance
nodePoolName := state.Attributes["name"]
kubernetesClusterId := state.Attributes["kubernetes_cluster_id"]
parsedK8sId, err := commonids.ParseKubernetesClusterID(kubernetesClusterId)

if err != nil {
return fmt.Errorf("parsing kubernetes cluster id: %+v", err)
}
Expand All @@ -1152,6 +1154,9 @@ func (KubernetesClusterNodePoolResource) scaleNodePool(nodeCount int) acceptance

nodePool.Model.Properties.Count = utils.Int64(int64(nodeCount))

ctx, cancel := context.WithDeadline(clients.StopContext, time.Now().Add(1*time.Hour))
defer cancel()

err = clients.Containers.AgentPoolsClient.CreateOrUpdateThenPoll(ctx, parsedAgentPoolId, *nodePool.Model)
if err != nil {
return fmt.Errorf("Bad: updating node pool %q: %+v", nodePoolName, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"testing"
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
Expand Down Expand Up @@ -237,6 +238,9 @@ func (KubernetesClusterResource) updateDefaultNodePoolAgentCount(nodeCount int)

nodePool.Model.Properties.Count = utils.Int64(int64(nodeCount))

ctx, cancel := context.WithDeadline(clients.StopContext, time.Now().Add(1*time.Hour))
defer cancel()

err = clients.Containers.AgentPoolsClient.CreateOrUpdateThenPoll(ctx, agentPoolId, *nodePool.Model)
if err != nil {
return fmt.Errorf("Bad: updating node pool %q: %+v", nodePoolName, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"regexp"
"testing"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
Expand Down Expand Up @@ -73,6 +74,9 @@ func TestAccKubernetesCluster_updateVmSizeAfterFailureWithTempAndDefault(t *test
profile.Name = &tempNodePoolName
profile.Properties.VMSize = pointer.To("Standard_DS3_v2")

ctx, cancel := context.WithDeadline(clients.StopContext, time.Now().Add(1*time.Hour))
defer cancel()

tempNodePoolId := agentpools.NewAgentPoolID(id.SubscriptionId, id.ResourceGroupName, id.ManagedClusterName, tempNodePoolName)
if err := client.CreateOrUpdateThenPoll(ctx, tempNodePoolId, *profile); err != nil {
return fmt.Errorf("creating %s: %+v", tempNodePoolId, err)
Expand Down Expand Up @@ -126,6 +130,9 @@ func TestAccKubernetesCluster_updateVmSizeAfterFailureWithTempWithoutDefault(t *
profile.Name = &tempNodePoolName
profile.Properties.VMSize = pointer.To("Standard_DS3_v2")

ctx, cancel := context.WithDeadline(clients.StopContext, time.Now().Add(1*time.Hour))
defer cancel()

tempNodePoolId := agentpools.NewAgentPoolID(id.SubscriptionId, id.ResourceGroupName, id.ManagedClusterName, tempNodePoolName)
if err := client.CreateOrUpdateThenPoll(ctx, tempNodePoolId, *profile); err != nil {
return fmt.Errorf("creating %s: %+v", tempNodePoolId, err)
Expand Down

0 comments on commit 59f8cab

Please sign in to comment.