Skip to content

Commit

Permalink
acceptance test
Browse files Browse the repository at this point in the history
  • Loading branch information
asalan316 committed Sep 20, 2024
1 parent b4d5a67 commit c217dd7
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 54 deletions.
1 change: 1 addition & 0 deletions devbox.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,7 @@
},
"ruby@latest": {
"last_modified": "2024-09-12T11:58:09Z",
"plugin_version": "0.0.2",
"resolved": "github:NixOS/nixpkgs/280db3decab4cbeb22a4599bd472229ab74d25e1#ruby",
"source": "devbox-search",
"version": "3.3.4",
Expand Down
8 changes: 6 additions & 2 deletions src/acceptance/app/app_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ var (
instanceName string
initialInstanceCount int

appName string
appGUID string
appName string
appToScaleGUID string

neighbourAppName string

neighbourAppGUID string
)

const componentName = "Application Scale Suite"
Expand Down
8 changes: 4 additions & 4 deletions src/acceptance/app/cf_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ var _ = Describe("AutoScaler CF metadata support", func() {
BeforeEach(func() {
policy = GenerateDynamicScaleOutAndInPolicy(1, 2, "test_metric", 500, 500)
appName = CreateTestApp(cfg, "labeled-go_app", 1)
appGUID, err = GetAppGuid(cfg, appName)
appToScaleGUID, err = GetAppGuid(cfg, appName)
Expect(err).NotTo(HaveOccurred())
instanceName = CreatePolicy(cfg, appName, appGUID, policy)
instanceName = CreatePolicy(cfg, appName, appToScaleGUID, policy)
StartApp(appName, cfg.CfPushTimeoutDuration())
})
AfterEach(AppAfterEach)

When("the label app-autoscaler.cloudfoundry.org/disable-autoscaling is set", func() {
It("should not scale out", func() {
By("Set the label app-autoscaler.cloudfoundry.org/disable-autoscaling to true")
SetLabel(cfg, appGUID, "app-autoscaler.cloudfoundry.org/disable-autoscaling", "true")
scaleOut := sendMetricToAutoscaler(cfg, appGUID, appName, 550, true)
SetLabel(cfg, appToScaleGUID, "app-autoscaler.cloudfoundry.org/disable-autoscaling", "true")
scaleOut := sendMetricToAutoscaler(cfg, appToScaleGUID, appName, 550, true)
Consistently(scaleOut).
WithTimeout(5 * time.Minute).
WithPolling(15 * time.Second).
Expand Down
58 changes: 49 additions & 9 deletions src/acceptance/app/custom_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"acceptance"
"acceptance/config"
. "acceptance/helpers"
"fmt"
"time"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -18,9 +19,9 @@ var _ = Describe("AutoScaler custom metrics policy", func() {
BeforeEach(func() {
policy = GenerateDynamicScaleOutAndInPolicy(1, 2, "test_metric", 500, 500)
appName = CreateTestApp(cfg, "node-custom-metric", 1)
appGUID, err = GetAppGuid(cfg, appName)
appToScaleGUID, err = GetAppGuid(cfg, appName)
Expect(err).NotTo(HaveOccurred())
instanceName = CreatePolicy(cfg, appName, appGUID, policy)
instanceName = CreatePolicy(cfg, appName, appToScaleGUID, policy)
StartApp(appName, cfg.CfPushTimeoutDuration())
})
AfterEach(AppAfterEach)
Expand All @@ -30,14 +31,14 @@ var _ = Describe("AutoScaler custom metrics policy", func() {
Context("when scaling by custom metrics", func() {
It("should scale out and scale in", Label(acceptance.LabelSmokeTests), func() {
By("Scale out to 2 instances")
scaleOut := sendMetricToAutoscaler(cfg, appGUID, appName, 550, false)
scaleOut := sendMetricToAutoscaler(cfg, appToScaleGUID, appName, 550, false)
Eventually(scaleOut).
WithTimeout(5 * time.Minute).
WithPolling(15 * time.Second).
Should(Equal(2))

By("Scale in to 1 instances")
scaleIn := sendMetricToAutoscaler(cfg, appGUID, appName, 100, false)
scaleIn := sendMetricToAutoscaler(cfg, appToScaleGUID, appName, 100, false)
Eventually(scaleIn).
WithTimeout(5 * time.Minute).
WithPolling(15 * time.Second).
Expand All @@ -49,14 +50,41 @@ var _ = Describe("AutoScaler custom metrics policy", func() {
Context("when scaling by custom metrics via mtls", func() {
It("should scale out and scale in", Label(acceptance.LabelSmokeTests), func() {
By("Scale out to 2 instances")
scaleOut := sendMetricToAutoscaler(cfg, appGUID, appName, 550, true)
scaleOut := sendMetricToAutoscaler(cfg, appToScaleGUID, appName, 550, true)
Eventually(scaleOut).
WithTimeout(5 * time.Minute).
WithPolling(15 * time.Second).
Should(Equal(2))

By("Scale in to 1 instance")
scaleIn := sendMetricToAutoscaler(cfg, appGUID, appName, 100, true)
scaleIn := sendMetricToAutoscaler(cfg, appToScaleGUID, appName, 100, true)
Eventually(scaleIn).
WithTimeout(5 * time.Minute).
WithPolling(15 * time.Second).
Should(Equal(1))

})
})

FContext("neighbour app send custom metrics for another app via mtls", func() {
JustBeforeEach(func() {
neighbourAppName = CreateTestApp(cfg, "go-neighbour-app", 1)
neighbourAppGUID, err = GetAppGuid(cfg, neighbourAppName)
Expect(err).NotTo(HaveOccurred())
// BindServiceToApp(cfg, neighbourAppName, instanceName)
BindServiceToAppWithPolicy(cfg, neighbourAppName, instanceName, policy)
StartApp(neighbourAppName, cfg.CfPushTimeoutDuration())
})
It("should scale out and scale in", Label(acceptance.LabelSmokeTests), func() {
By(fmt.Sprintf("Scale out %s to 2 instance", appName))
scaleOut := sendMetricToAutoscaler(cfg, appToScaleGUID, neighbourAppName, 550, true)
Eventually(scaleOut).
WithTimeout(5 * time.Minute).
WithPolling(15 * time.Second).
Should(Equal(2))

By(fmt.Sprintf("Scale in %s to 1 instance", appName))
scaleIn := sendMetricToAutoscaler(cfg, appToScaleGUID, neighbourAppName, 100, true)
Eventually(scaleIn).
WithTimeout(5 * time.Minute).
WithPolling(15 * time.Second).
Expand All @@ -66,13 +94,25 @@ var _ = Describe("AutoScaler custom metrics policy", func() {
})
})

func sendMetricToAutoscaler(config *config.Config, appGUID string, appName string, metricThreshold int, mtls bool) func() (int, error) {
func sendMetricFromNeighbourApp(config *config.Config, appToScaleGUID string, neighbourAppGUID string, metricThreshold int, mtls bool) func() (int, error) {
return func() (int, error) {
if mtls {
SendMetricMTLS(config, appName, metricThreshold)
SendMetricMTLS(config, appToScaleGUID, appName, metricThreshold)
} else {
SendMetric(config, appName, metricThreshold)
}
return RunningInstances(appGUID, 5*time.Second)
return RunningInstances(appToScaleGUID, 5*time.Second)
}
}

func sendMetricToAutoscaler(config *config.Config, appToScaleGUID string, neighbourAppName string, metricThreshold int, mtls bool) func() (int, error) {
return func() (int, error) {

if mtls {
SendMetricMTLS(config, appToScaleGUID, neighbourAppName, metricThreshold)
} else {
SendMetric(config, neighbourAppName, metricThreshold)
}
return RunningInstances(appToScaleGUID, 5*time.Second)
}
}
36 changes: 18 additions & 18 deletions src/acceptance/app/dynamic_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ var _ = Describe("AutoScaler dynamic policy", func() {
JustBeforeEach(func() {
appName = CreateTestApp(cfg, "dynamic-policy", initialInstanceCount)

appGUID, err = GetAppGuid(cfg, appName)
appToScaleGUID, err = GetAppGuid(cfg, appName)
Expect(err).NotTo(HaveOccurred())
StartApp(appName, cfg.CfPushTimeoutDuration())
instanceName = CreatePolicy(cfg, appName, appGUID, policy)
instanceName = CreatePolicy(cfg, appName, appToScaleGUID, policy)
})
BeforeEach(func() {
maxHeapLimitMb = cfg.NodeMemoryLimit - minimalMemoryUsage
Expand All @@ -55,13 +55,13 @@ var _ = Describe("AutoScaler dynamic policy", func() {
CurlAppInstance(cfg, appName, 0, fmt.Sprintf("/memory/%d/5", int64(heapToUse)))

By("wait for scale to 2")
WaitForNInstancesRunning(appGUID, 2, 5*time.Minute)
WaitForNInstancesRunning(appToScaleGUID, 2, 5*time.Minute)

By("Drop memory used by app")
CurlAppInstance(cfg, appName, 0, "/memory/close")

By("Wait for scale to minimum instances")
WaitForNInstancesRunning(appGUID, 1, 5*time.Minute)
WaitForNInstancesRunning(appToScaleGUID, 1, 5*time.Minute)
})
})
})
Expand All @@ -81,13 +81,13 @@ var _ = Describe("AutoScaler dynamic policy", func() {
CurlAppInstance(cfg, appName, 0, fmt.Sprintf("/memory/%d/5", heapToUse))

By("Wait for scale to 2 instances")
WaitForNInstancesRunning(appGUID, 2, 5*time.Minute)
WaitForNInstancesRunning(appToScaleGUID, 2, 5*time.Minute)

By("drop memory used")
CurlAppInstance(cfg, appName, 0, "/memory/close")

By("Wait for scale down to 1 instance")
WaitForNInstancesRunning(appGUID, 1, 5*time.Minute)
WaitForNInstancesRunning(appToScaleGUID, 1, 5*time.Minute)
})
})
})
Expand Down Expand Up @@ -131,7 +131,7 @@ var _ = Describe("AutoScaler dynamic policy", func() {
})

It("should scale out", Label(acceptance.LabelSmokeTests), func() {
WaitForNInstancesRunning(appGUID, 2, 5*time.Minute)
WaitForNInstancesRunning(appToScaleGUID, 2, 5*time.Minute)
})
})

Expand Down Expand Up @@ -162,7 +162,7 @@ var _ = Describe("AutoScaler dynamic policy", func() {
})

It("should scale in", func() {
WaitForNInstancesRunning(appGUID, 1, 5*time.Minute)
WaitForNInstancesRunning(appToScaleGUID, 1, 5*time.Minute)
})
})

Expand Down Expand Up @@ -206,7 +206,7 @@ var _ = Describe("AutoScaler dynamic policy", func() {
})

It("should scale out", func() {
WaitForNInstancesRunning(appGUID, 2, 5*time.Minute)
WaitForNInstancesRunning(appToScaleGUID, 2, 5*time.Minute)
})
})

Expand Down Expand Up @@ -239,7 +239,7 @@ var _ = Describe("AutoScaler dynamic policy", func() {
It("should scale in", func() {
// because we are generating 20rps but starting with 2 instances,
// there should be on average 10rps per instance, which should trigger the scale in
WaitForNInstancesRunning(appGUID, 1, 5*time.Minute)
WaitForNInstancesRunning(appToScaleGUID, 1, 5*time.Minute)
})
})
})
Expand All @@ -255,13 +255,13 @@ var _ = Describe("AutoScaler dynamic policy", func() {
It("when cpu is greater than scaling out threshold", func() {
By("should scale out to 2 instances")
StartCPUUsage(cfg, appName, int(float64(cfg.CPUUpperThreshold)*0.9), 5)
WaitForNInstancesRunning(appGUID, 2, 5*time.Minute)
WaitForNInstancesRunning(appToScaleGUID, 2, 5*time.Minute)

By("should scale in to 1 instance after cpu usage is reduced")
//only hit the one instance that was asked to run hot.
StopCPUUsage(cfg, appName, 0)

WaitForNInstancesRunning(appGUID, 1, 10*time.Minute)
WaitForNInstancesRunning(appToScaleGUID, 1, 10*time.Minute)
})
})

Expand Down Expand Up @@ -290,11 +290,11 @@ var _ = Describe("AutoScaler dynamic policy", func() {
// cpuutil will be 100% if cpu usage is reaching the value of cpu entitlement
maxCPUUsage := cfg.CPUUtilScalingPolicyTest.AppCPUEntitlement
StartCPUUsage(cfg, appName, maxCPUUsage, 5)
WaitForNInstancesRunning(appGUID, 2, 5*time.Minute)
WaitForNInstancesRunning(appToScaleGUID, 2, 5*time.Minute)

// only hit the one instance that was asked to run hot
StopCPUUsage(cfg, appName, 0)
WaitForNInstancesRunning(appGUID, 1, 5*time.Minute)
WaitForNInstancesRunning(appToScaleGUID, 1, 5*time.Minute)
})
})

Expand All @@ -308,11 +308,11 @@ var _ = Describe("AutoScaler dynamic policy", func() {
ScaleDisk(cfg, appName, "1GB")

StartDiskUsage(cfg, appName, 800, 5)
WaitForNInstancesRunning(appGUID, 2, 5*time.Minute)
WaitForNInstancesRunning(appToScaleGUID, 2, 5*time.Minute)

// only hit the one instance that was asked to occupy disk space
StopDiskUsage(cfg, appName, 0)
WaitForNInstancesRunning(appGUID, 1, 5*time.Minute)
WaitForNInstancesRunning(appToScaleGUID, 1, 5*time.Minute)
})
})

Expand All @@ -326,11 +326,11 @@ var _ = Describe("AutoScaler dynamic policy", func() {
ScaleDisk(cfg, appName, "1GB")

StartDiskUsage(cfg, appName, 800, 5)
WaitForNInstancesRunning(appGUID, 2, 5*time.Minute)
WaitForNInstancesRunning(appToScaleGUID, 2, 5*time.Minute)

// only hit the one instance that was asked to occupy disk space
StopDiskUsage(cfg, appName, 0)
WaitForNInstancesRunning(appGUID, 1, 5*time.Minute)
WaitForNInstancesRunning(appToScaleGUID, 1, 5*time.Minute)
})
})
})
Expand Down
8 changes: 4 additions & 4 deletions src/acceptance/app/lead_times_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ var _ = Describe("Autoscaler lead times for scaling", func() {
BeforeEach(func() {
policy = GenerateDynamicScaleOutAndInPolicy(1, 2, "test_metric", 500, 500)
appName = CreateTestApp(cfg, "labeled-go_app", 1)
appGUID, err = GetAppGuid(cfg, appName)
appToScaleGUID, err = GetAppGuid(cfg, appName)
Expect(err).NotTo(HaveOccurred())
instanceName = CreatePolicy(cfg, appName, appGUID, policy)
instanceName = CreatePolicy(cfg, appName, appToScaleGUID, policy)
StartApp(appName, cfg.CfPushTimeoutDuration())
})
AfterEach(AppAfterEach)
Expand All @@ -29,8 +29,8 @@ var _ = Describe("Autoscaler lead times for scaling", func() {
coolDown := TestCoolDownSeconds * time.Second
scalingTimewindow := 130 * time.Second // be friendly and allow some time for "internal autoscaler processes" (metric polling interval etc.) to take place before actual scaling happens

sendMetricForScaleOutAndReturnNumInstancesFunc := sendMetricToAutoscaler(cfg, appGUID, appName, 510, false)
sendMetricForScaleInAndReturnNumInstancesFunc := sendMetricToAutoscaler(cfg, appGUID, appName, 490, false)
sendMetricForScaleOutAndReturnNumInstancesFunc := sendMetricToAutoscaler(cfg, appToScaleGUID, appName, 510, false)
sendMetricForScaleInAndReturnNumInstancesFunc := sendMetricToAutoscaler(cfg, appToScaleGUID, appName, 490, false)

By("checking that no scaling out happens before breach_duration_secs have passed")
Consistently(sendMetricForScaleOutAndReturnNumInstancesFunc).
Expand Down
10 changes: 5 additions & 5 deletions src/acceptance/app/recurring_schedule_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var _ = Describe("AutoScaler recurring schedule policy", func() {
instanceName = CreateService(cfg)
initialInstanceCount = 1
appName = CreateTestApp(cfg, "recurring-schedule", initialInstanceCount)
appGUID, err = GetAppGuid(cfg, appName)
appToScaleGUID, err = GetAppGuid(cfg, appName)
Expect(err).NotTo(HaveOccurred())
})
AfterEach(AppAfterEach)
Expand All @@ -36,21 +36,21 @@ var _ = Describe("AutoScaler recurring schedule policy", func() {
JustBeforeEach(func() {
startTime, endTime = getStartAndEndTime(time.UTC, 70*time.Second, time.Duration(interval+120)*time.Second)
policy = GenerateDynamicAndRecurringSchedulePolicy(instanceMinCount, 4, 50, "UTC", startTime, endTime, daysOfMonthOrWeek, scheduleInstanceMinCount, 5, scheduleInitialMinInstanceCount)
instanceName = CreatePolicy(cfg, appName, appGUID, policy)
instanceName = CreatePolicy(cfg, appName, appToScaleGUID, policy)
StartApp(appName, cfg.CfPushTimeoutDuration())
})

scaleDown := func() {
By("setting to initial_min_instance_count")
jobRunTime := time.Until(startTime.Add(5 * time.Minute))
WaitForNInstancesRunning(appGUID, scheduleInitialMinInstanceCount, jobRunTime, "The schedule should initially trigger scaling to initial_min_instance_count %i", scheduleInitialMinInstanceCount)
WaitForNInstancesRunning(appToScaleGUID, scheduleInitialMinInstanceCount, jobRunTime, "The schedule should initially trigger scaling to initial_min_instance_count %i", scheduleInitialMinInstanceCount)

By("setting schedule's instance_min_count")
jobRunTime = time.Until(endTime)
WaitForNInstancesRunning(appGUID, scheduleInstanceMinCount, jobRunTime, "The schedule should allow scaling down to instance_min_count %i", scheduleInstanceMinCount)
WaitForNInstancesRunning(appToScaleGUID, scheduleInstanceMinCount, jobRunTime, "The schedule should allow scaling down to instance_min_count %i", scheduleInstanceMinCount)

By("setting to default instance_min_count")
WaitForNInstancesRunning(appGUID, instanceMinCount, time.Until(endTime.Add(time.Duration(interval+60)*time.Second)), "After the schedule ended scaling down to instance_min_count %i should be possible", instanceMinCount)
WaitForNInstancesRunning(appToScaleGUID, instanceMinCount, time.Until(endTime.Add(time.Duration(interval+60)*time.Second)), "After the schedule ended scaling down to instance_min_count %i should be possible", instanceMinCount)
}

Context("with days of month", func() {
Expand Down
12 changes: 6 additions & 6 deletions src/acceptance/app/specificdate_schedule_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var _ = Describe("AutoScaler specific date schedule policy", func() {
instanceName = CreateService(cfg)
initialInstanceCount = 1
appName = CreateTestApp(cfg, "date-schedule", initialInstanceCount)
appGUID, err = GetAppGuid(cfg, appName)
appToScaleGUID, err = GetAppGuid(cfg, appName)
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -39,17 +39,17 @@ var _ = Describe("AutoScaler specific date schedule policy", func() {
endDateTime = startDateTime.Add(time.Duration(interval+120) * time.Second)

policy = GenerateSpecificDateSchedulePolicy(startDateTime, endDateTime, scheduleInstanceMin, scheduleInstanceMax, scheduledInstanceInit)
instanceName = CreatePolicy(cfg, appName, appGUID, policy)
instanceName = CreatePolicy(cfg, appName, appToScaleGUID, policy)
})

It("should scale", func() {
pollTime := 15 * time.Second
By(fmt.Sprintf("waiting for scheduledInstanceInit: %d", scheduledInstanceInit))
WaitForNInstancesRunning(appGUID, 3, time.Until(startDateTime.Add(1*time.Minute)))
WaitForNInstancesRunning(appToScaleGUID, 3, time.Until(startDateTime.Add(1*time.Minute)))

By(fmt.Sprintf("waiting for scheduleInstanceMin: %d", scheduleInstanceMin))
jobRunTime := time.Until(endDateTime)
Eventually(func() (int, error) { return RunningInstances(appGUID, cfg.DefaultTimeoutDuration()) }).
Eventually(func() (int, error) { return RunningInstances(appToScaleGUID, cfg.DefaultTimeoutDuration()) }).
//+/- poll time error margin.
WithTimeout(jobRunTime + pollTime).
WithPolling(pollTime).
Expand All @@ -58,12 +58,12 @@ var _ = Describe("AutoScaler specific date schedule policy", func() {
//+/- poll time error margin.
timeout := time.Until(endDateTime) - pollTime
By(fmt.Sprintf("waiting till end of schedule %dS and should stay %d instances", int(timeout.Seconds()), scheduleInstanceMin))
Consistently(func() (int, error) { return RunningInstances(appGUID, jobRunTime) }).
Consistently(func() (int, error) { return RunningInstances(appToScaleGUID, jobRunTime) }).
WithTimeout(timeout).
WithPolling(pollTime).
Should(Equal(2))

WaitForNInstancesRunning(appGUID, 1, time.Duration(interval+60)*time.Second)
WaitForNInstancesRunning(appToScaleGUID, 1, time.Duration(interval+60)*time.Second)
})
})
})
Loading

0 comments on commit c217dd7

Please sign in to comment.