Skip to content

Commit

Permalink
use helper WaitForDeploymentScale
Browse files Browse the repository at this point in the history
  • Loading branch information
izabelacg committed Jun 5, 2024
1 parent c27264e commit 420ad05
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions test/ha/workload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/watch"
pkgTest "knative.dev/pkg/test"
"knative.dev/serving/pkg/apis/autoscaling"
"knative.dev/serving/pkg/apis/serving"
rtesting "knative.dev/serving/pkg/testing/v1"
Expand All @@ -40,6 +41,7 @@ import (
const (
minimumNumberOfReplicas = 2
maximumNumberOfReplicas = 2
deploymentSuffix = "-deployment"
)

func TestActivatorNotInRequestPath(t *testing.T) {
Expand Down Expand Up @@ -100,8 +102,12 @@ func testUptimeDuringUserPodDeletion(t *testing.T, ctx context.Context, clients
prober.Spawn(resources.Service.Status.URL.URL())
defer assertSLO(t, prober, 1)

// Get user pods
deploymentName := names.Revision + deploymentSuffix
if err := pkgTest.WaitForDeploymentScale(ctx, clients.KubeClient, deploymentName, test.ServingFlags.TestNamespace, minimumNumberOfReplicas); err != nil {
t.Fatalf("Deployment %s not scaled to %d: %v", deploymentName, minimumNumberOfReplicas, err)
}

// Get user pods
selector := labels.SelectorFromSet(labels.Set{
serving.ServiceLabelKey: names.Service,
})
Expand All @@ -110,10 +116,6 @@ func testUptimeDuringUserPodDeletion(t *testing.T, ctx context.Context, clients
t.Fatalf("Unable to get pods: %v", err)
}

if !(len(pods.Items) == minimumNumberOfReplicas) {
t.Fatalf("Expected to have %d user pod(s) running, but found %d.", minimumNumberOfReplicas, len(pods.Items))
}

t.Logf("Watching user pods")
var wg sync.WaitGroup
wg.Add(2)
Expand All @@ -137,8 +139,8 @@ func testUptimeDuringUserPodDeletion(t *testing.T, ctx context.Context, clients
t.Fatalf("Unable to get pods: %v", err)
}

if !(len(newPods.Items) == minimumNumberOfReplicas) {
t.Errorf("Expected to have %d user pod(s) running, but found %d.", minimumNumberOfReplicas, len(newPods.Items))
if err := pkgTest.WaitForDeploymentScale(ctx, clients.KubeClient, deploymentName, test.ServingFlags.TestNamespace, minimumNumberOfReplicas); err != nil {
t.Errorf("Deployment %s not scaled to %d: %v", deploymentName, minimumNumberOfReplicas, err)
}
}

Expand Down

0 comments on commit 420ad05

Please sign in to comment.