Skip to content

Commit

Permalink
Adds e2e test for activation-scale (knative#13197)
Browse files Browse the repository at this point in the history
* cleanup

Signed-off-by: Paul S. Schweigert <paulschw@us.ibm.com>

* adds e2e test for activation-scale

Signed-off-by: Paul S. Schweigert <paulschw@us.ibm.com>

* fix import

Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com>

* remove debugging logs

Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com>

* use correct URL

Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com>

---------

Signed-off-by: Paul S. Schweigert <paulschw@us.ibm.com>
Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com>
  • Loading branch information
psschwei authored Mar 6, 2023
1 parent b285cb4 commit 5e3b4af
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/kind-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,5 @@ jobs:
if: ${{ failure() }}
with:
cluster-resources: nodes,namespaces,crds,${{ matrix.cluster-resources || '' }}
namespace-resources: pods,svc,ksvc,route,configuration,revision,king,${{ matrix.namespace-resources || '' }}
namespace-resources: configmaps,pods,svc,ksvc,route,configuration,revision,king,${{ matrix.namespace-resources || '' }}
artifact-name: logs-${{ matrix.k8s-version}}-${{ matrix.ingress }}-${{ matrix.test-suite }}
69 changes: 69 additions & 0 deletions test/e2e/autoscale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ package e2e

import (
"context"
"net/http"
"strconv"
"strings"
"testing"
"time"
Expand All @@ -39,6 +41,7 @@ import (
"knative.dev/serving/pkg/resources"
rtesting "knative.dev/serving/pkg/testing/v1"
"knative.dev/serving/test"
testv1 "knative.dev/serving/test/v1"
)

func TestAutoscaleUpDownUp(t *testing.T) {
Expand Down Expand Up @@ -346,3 +349,69 @@ func TestFastScaleToZero(t *testing.T) {

t.Log("Total time to scale down:", time.Since(st))
}

const activationScale = 5

func TestActivationScale(t *testing.T) {
t.Parallel()

ctx := SetupSvc(t,
&AutoscalerOptions{
Class: autoscaling.KPA,
Metric: autoscaling.Concurrency,
Target: 6,
TargetUtilization: 0.7},
test.Options{},
rtesting.WithConfigAnnotations(map[string]string{
autoscaling.ActivationScaleKey: strconv.Itoa(activationScale),
}))
test.EnsureTearDown(t, ctx.Clients(), ctx.Names())

clients := ctx.Clients()
resources, err := testv1.GetResourceObjects(clients, *ctx.names)
if err != nil {
t.Errorf("error: unable to update resource: %s", err)
}

// initial scale of revision
if err := wait.Poll(1*time.Second, 5*time.Minute, func() (bool, error) {
return *resources.Revision.Status.ActualReplicas > 0, nil
}); err != nil {
t.Errorf("error: revision never had active pods")
}

// scale to zero
if err := wait.Poll(1*time.Second, 5*time.Minute, func() (bool, error) {
resources, _ = testv1.GetResourceObjects(clients, *ctx.names)
return *resources.Revision.Status.ActualReplicas == 0, nil
}); err != nil {
t.Errorf("error: revision never scaled to zero")
}

target, err := getVegetaTarget(
ctx.clients.KubeClient, ctx.resources.Route.Status.URL.URL().Hostname(),
pkgtest.Flags.IngressEndpoint, test.ServingFlags.ResolvableDomain, "sleep", autoscaleSleep)
if err != nil {
t.Errorf("error creating vegeta target: %v", err)
}

// send request, should scale up to activation scale
client := http.Client{}
req, err := http.NewRequest("GET", target.URL, nil)
if err != nil {
t.Errorf("unable to create request: %v", err)
}
req.Host = target.Header["Host"][0]
_, err = client.Do(req)
if err != nil {
t.Errorf("unable to send request to service: %v", err)
}

// wait for revision desired replicas to equal activation scale
if err := wait.Poll(1*time.Second, 5*time.Minute, func() (bool, error) {
resources, _ = testv1.GetResourceObjects(clients, *ctx.names)
return *resources.Revision.Status.DesiredReplicas == activationScale, nil
}); err != nil {
t.Errorf("error: desired pods never equal to activation scale")
}
}
2 changes: 0 additions & 2 deletions test/e2e/resource_quota_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ func TestResourceQuotaError(t *testing.T) {
t.Fatalf("Failed to create Service %s: %v", names.Service, err)
}

t.Log("Service created")

names.Config = serviceresourcenames.Configuration(svc)
var cond *apis.Condition
err = v1test.WaitForServiceState(clients.ServingClient, names.Service, func(r *v1.Service) (bool, error) {
Expand Down

0 comments on commit 5e3b4af

Please sign in to comment.