From 7bf911769eea44c13be6caab0bb41a8a04be481b Mon Sep 17 00:00:00 2001 From: Josef Karasek Date: Fri, 28 Jun 2024 10:50:47 +0200 Subject: [PATCH] update tests Signed-off-by: Josef Karasek --- pkg/scaling/scale_handler_test.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pkg/scaling/scale_handler_test.go b/pkg/scaling/scale_handler_test.go index 7a822c163a8..563fd90f36b 100644 --- a/pkg/scaling/scale_handler_test.go +++ b/pkg/scaling/scale_handler_test.go @@ -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 { @@ -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()) @@ -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()) @@ -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{ @@ -800,6 +804,7 @@ func newScalerTestData( Scaler4AverageValue: int64(scaler4AverageValue), Scaler4IsActive: scaler4IsActive, ResultIsActive: resultIsActive, + ResultIsError: resultIsError, ResultQueueLength: int64(resultQueueLength), ResultMaxValue: int64(resultMaxLength), } @@ -822,6 +827,7 @@ type scalerTestData struct { Scaler4AverageValue int64 Scaler4IsActive bool ResultIsActive bool + ResultIsError bool ResultQueueLength int64 ResultMaxValue int64 MinReplicaCount int32