faas/gateway/handlers/alerthandler_test.go
Alex Ellis (VMware) f5939c9a60 Update for scaling edge-case
- as reported on Slack and in issue #931 the gateway scaling code
was scaling to zero replicas as a result of the "proportional
scaling" added by @Templum's PR. This commit added a failing test
which was fixed by adding boundary checking - now if the scaling
amount is "0" we keep the current amount of replicas.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-10-25 11:47:47 +01:00

100 lines
2.8 KiB
Go

// Copyright (c) Alex Ellis 2017. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package handlers
import (
"testing"
)
func TestDisabledScale(t *testing.T) {
minReplicas := uint64(1)
scalingFactor := uint64(0)
newReplicas := CalculateReplicas("firing", DefaultMinReplicas, DefaultMaxReplicas, minReplicas, scalingFactor)
if newReplicas != minReplicas {
t.Logf("Expected not to scale, but replicas were: %d", newReplicas)
t.Fail()
}
}
func TestParameterEdge(t *testing.T) {
minReplicas := uint64(0)
scalingFactor := uint64(0)
newReplicas := CalculateReplicas("firing", DefaultMinReplicas, DefaultMaxReplicas, minReplicas, scalingFactor)
if newReplicas != 0 {
t.Log("Expected not to scale")
t.Fail()
}
}
func TestScalingWithSameUpperLowerLimit(t *testing.T) {
minReplicas := uint64(1)
scalingFactor := uint64(20)
// status string, currentReplicas uint64, maxReplicas uint64, minReplicas uint64, scalingFactor uint64)
newReplicas := CalculateReplicas("firing", minReplicas, minReplicas, minReplicas, scalingFactor)
if newReplicas != 1 {
t.Logf("Replicas - want: %d, got: %d", minReplicas, newReplicas)
t.Fail()
}
}
func TestMaxScale(t *testing.T) {
minReplicas := uint64(1)
scalingFactor := uint64(100)
newReplicas := CalculateReplicas("firing", DefaultMinReplicas, DefaultMaxReplicas, minReplicas, scalingFactor)
if newReplicas != 20 {
t.Log("Expected ceiling of 20 replicas")
t.Fail()
}
}
func TestInitialScale(t *testing.T) {
minReplicas := uint64(1)
scalingFactor := uint64(20)
newReplicas := CalculateReplicas("firing", DefaultMinReplicas, DefaultMaxReplicas, minReplicas, scalingFactor)
if newReplicas != 4 {
t.Log("Expected the increment to equal 4")
t.Fail()
}
}
func TestScale(t *testing.T) {
minReplicas := uint64(1)
scalingFactor := uint64(20)
newReplicas := CalculateReplicas("firing", 4, DefaultMaxReplicas, minReplicas, scalingFactor)
if newReplicas != 8 {
t.Log("Expected newReplicas to equal 8")
t.Fail()
}
}
func TestScaleCeiling(t *testing.T) {
minReplicas := uint64(1)
scalingFactor := uint64(20)
newReplicas := CalculateReplicas("firing", 20, DefaultMaxReplicas, minReplicas, scalingFactor)
if newReplicas != 20 {
t.Log("Expected ceiling of 20 replicas")
t.Fail()
}
}
func TestScaleCeilingEdge(t *testing.T) {
minReplicas := uint64(1)
scalingFactor := uint64(20)
newReplicas := CalculateReplicas("firing", 19, DefaultMaxReplicas, minReplicas, scalingFactor)
if newReplicas != 20 {
t.Log("Expected ceiling of 20 replicas")
t.Fail()
}
}
func TestBackingOff(t *testing.T) {
minReplicas := uint64(1)
scalingFactor := uint64(20)
newReplicas := CalculateReplicas("resolved", 8, DefaultMaxReplicas, minReplicas, scalingFactor)
if newReplicas != 1 {
t.Log("Expected backing off to 1 replica")
t.Fail()
}
}