Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Josef Karasek <josef@kedify.io>
  • Loading branch information
josefkarasek committed Jun 28, 2024
1 parent c522f25 commit 7bf9117
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions pkg/scaling/scale_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,19 +661,20 @@ func TestIsScaledJobActive(t *testing.T) {
scalerCachesLock: &sync.RWMutex{},
scaledObjectsMetricCache: metricscache.NewMetricsCache(),
}
isActive, queueLength, maxValue := sh.isScaledJobActive(context.TODO(), scaledJobSingle)
isActive, isError, queueLength, maxValue := sh.isScaledJobActive(context.TODO(), scaledJobSingle)
assert.Equal(t, true, isActive)
assert.Equal(t, false, isError)
assert.Equal(t, int64(20), queueLength)
assert.Equal(t, int64(10), maxValue)
scalerCache.Close(context.Background())

// Test the valiation
scalerTestDatam := []scalerTestData{
newScalerTestData("s0-queueLength", 100, "max", 20, 1, true, 10, 2, true, 5, 3, true, 7, 4, false, true, 20, 20),
newScalerTestData("queueLength", 100, "min", 20, 1, true, 10, 2, true, 5, 3, true, 7, 4, false, true, 5, 2),
newScalerTestData("messageCount", 100, "avg", 20, 1, true, 10, 2, true, 5, 3, true, 7, 4, false, true, 12, 9),
newScalerTestData("s3-messageCount", 100, "sum", 20, 1, true, 10, 2, true, 5, 3, true, 7, 4, false, true, 35, 27),
newScalerTestData("s10-messageCount", 25, "sum", 20, 1, true, 10, 2, true, 5, 3, true, 7, 4, false, true, 35, 25),
newScalerTestData("s0-queueLength", 100, "max", 20, 1, true, 10, 2, true, 5, 3, true, 7, 4, false, true, false, 20, 20),
newScalerTestData("queueLength", 100, "min", 20, 1, true, 10, 2, true, 5, 3, true, 7, 4, false, true, false, 5, 2),
newScalerTestData("messageCount", 100, "avg", 20, 1, true, 10, 2, true, 5, 3, true, 7, 4, false, true, false, 12, 9),
newScalerTestData("s3-messageCount", 100, "sum", 20, 1, true, 10, 2, true, 5, 3, true, 7, 4, false, true, false, 35, 27),
newScalerTestData("s10-messageCount", 25, "sum", 20, 1, true, 10, 2, true, 5, 3, true, 7, 4, false, true, false, 35, 25),
}

for index, scalerTestData := range scalerTestDatam {
Expand Down Expand Up @@ -717,9 +718,10 @@ func TestIsScaledJobActive(t *testing.T) {
scaledObjectsMetricCache: metricscache.NewMetricsCache(),
}
fmt.Printf("index: %d", index)
isActive, queueLength, maxValue = sh.isScaledJobActive(context.TODO(), scaledJob)
isActive, isError, queueLength, maxValue = sh.isScaledJobActive(context.TODO(), scaledJob)
// assert.Equal(t, 5, index)
assert.Equal(t, scalerTestData.ResultIsActive, isActive)
assert.Equal(t, scalerTestData.ResultIsError, isError)
assert.Equal(t, scalerTestData.ResultQueueLength, queueLength)
assert.Equal(t, scalerTestData.ResultMaxValue, maxValue)
scalerCache.Close(context.Background())
Expand Down Expand Up @@ -757,8 +759,9 @@ func TestIsScaledJobActiveIfQueueEmptyButMinReplicaCountGreaterZero(t *testing.T
scaledObjectsMetricCache: metricscache.NewMetricsCache(),
}

isActive, queueLength, maxValue := sh.isScaledJobActive(context.TODO(), scaledJobSingle)
isActive, isError, queueLength, maxValue := sh.isScaledJobActive(context.TODO(), scaledJobSingle)
assert.Equal(t, true, isActive)
assert.Equal(t, false, isError)
assert.Equal(t, int64(0), queueLength)
assert.Equal(t, int64(0), maxValue)
scalerCache.Close(context.Background())
Expand All @@ -781,6 +784,7 @@ func newScalerTestData(
scaler4AverageValue int, //nolint:golint,unparam
scaler4IsActive bool, //nolint:golint,unparam
resultIsActive bool, //nolint:golint,unparam
resultIsError bool, //nolint:golint,unparam
resultQueueLength,
resultMaxLength int) scalerTestData {
return scalerTestData{
Expand All @@ -800,6 +804,7 @@ func newScalerTestData(
Scaler4AverageValue: int64(scaler4AverageValue),
Scaler4IsActive: scaler4IsActive,
ResultIsActive: resultIsActive,
ResultIsError: resultIsError,
ResultQueueLength: int64(resultQueueLength),
ResultMaxValue: int64(resultMaxLength),
}
Expand All @@ -822,6 +827,7 @@ type scalerTestData struct {
Scaler4AverageValue int64
Scaler4IsActive bool
ResultIsActive bool
ResultIsError bool
ResultQueueLength int64
ResultMaxValue int64
MinReplicaCount int32
Expand Down

0 comments on commit 7bf9117

Please sign in to comment.