Skip to content

Commit

Permalink
fixed test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
bharathguvvala committed Jul 15, 2024
1 parent 51e21f1 commit e014c1b
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions pkg/scaling/scale_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func TestGetScaledObjectMetrics_DirectCall(t *testing.T) {
recorder := record.NewFakeRecorder(1)
mockClient := mock_client.NewMockClient(ctrl)
mockExecutor := mock_executor.NewMockScaleExecutor(ctrl)
//mockStatusWriter := mock_client.NewMockStatusWriter(ctrl)

metricsSpecs := []v2.MetricSpec{createMetricSpec(10, metricName)}
metricValue := scalers.GenerateMetricInMili(metricName, float64(10))
Expand Down Expand Up @@ -130,8 +129,7 @@ func TestGetScaledObjectMetrics_DirectCall(t *testing.T) {
mockExecutor.EXPECT().RequestScale(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
sh.checkScalers(context.TODO(), &scaledObject, &sync.RWMutex{})

//mockClient.EXPECT().Status().Return(mockStatusWriter)
//mockStatusWriter.EXPECT().Patch(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
expectNoStatusPatch(ctrl)
scaler.EXPECT().GetMetricSpecForScaling(gomock.Any()).Return(metricsSpecs)
// hitting directly GetMetricsAndActivity()
scaler.EXPECT().GetMetricsAndActivity(gomock.Any(), gomock.Any()).Return([]external_metrics.ExternalMetricValue{metricValue}, true, nil)
Expand All @@ -153,7 +151,6 @@ func TestGetScaledObjectMetrics_FromCache(t *testing.T) {
recorder := record.NewFakeRecorder(1)
mockClient := mock_client.NewMockClient(ctrl)
mockExecutor := mock_executor.NewMockScaleExecutor(ctrl)
//mockStatusWriter := mock_client.NewMockStatusWriter(ctrl)

metricsSpecs := []v2.MetricSpec{createMetricSpec(10, metricName)}
metricValue := scalers.GenerateMetricInMili(metricName, float64(10))
Expand Down Expand Up @@ -221,8 +218,7 @@ func TestGetScaledObjectMetrics_FromCache(t *testing.T) {
mockExecutor.EXPECT().RequestScale(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
sh.checkScalers(context.TODO(), &scaledObject, &sync.RWMutex{})

//mockClient.EXPECT().Status().Return(mockStatusWriter)
//mockStatusWriter.EXPECT().Patch(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
expectNoStatusPatch(ctrl)
scaler.EXPECT().GetMetricSpecForScaling(gomock.Any()).Return(metricsSpecs)
// hitting cache here instead of calling GetMetricsAndActivity()
metrics, err := sh.GetScaledObjectMetrics(context.TODO(), scaledObjectName, scaledObjectNamespace, metricName)
Expand Down Expand Up @@ -259,7 +255,6 @@ func TestGetScaledObjectMetrics_InParallel(t *testing.T) {
recorder := record.NewFakeRecorder(1)
mockClient := mock_client.NewMockClient(ctrl)
mockExecutor := mock_executor.NewMockScaleExecutor(ctrl)
//mockStatusWriter := mock_client.NewMockStatusWriter(ctrl)

scalerCollection := []*mock_scalers.MockScaler{}

Expand Down Expand Up @@ -353,8 +348,8 @@ func TestGetScaledObjectMetrics_InParallel(t *testing.T) {
return true
}, 1*time.Second, 400*time.Millisecond, "timeout exceeded: scalers not processed in parallel during `checkScalers`")

//mockClient.EXPECT().Status().Times(len(metricNames)).Return(mockStatusWriter)
//mockStatusWriter.EXPECT().Patch(gomock.Any(), gomock.Any(), gomock.Any()).Times(len(metricNames)).Return(nil)
expectNoStatusPatch(ctrl)

for i := 0; i < len(metricNames); i++ {
i := i
scalerCollection[i].EXPECT().GetMetricSpecForScaling(gomock.Any()).Return(metricsSpecFn(i))
Expand Down Expand Up @@ -907,7 +902,6 @@ func TestScalingModifiersFormula(t *testing.T) {
recorder := record.NewFakeRecorder(1)
mockClient := mock_client.NewMockClient(ctrl)
mockExecutor := mock_executor.NewMockScaleExecutor(ctrl)
//mockStatusWriter := mock_client.NewMockStatusWriter(ctrl)

metricsSpecs1 := []v2.MetricSpec{createMetricSpec(2, metricName1)}
metricsSpecs2 := []v2.MetricSpec{createMetricSpec(5, metricName2)}
Expand Down Expand Up @@ -998,8 +992,8 @@ func TestScalingModifiersFormula(t *testing.T) {
mockExecutor.EXPECT().RequestScale(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
sh.checkScalers(context.TODO(), &scaledObject, &sync.RWMutex{})

//mockClient.EXPECT().Status().Return(mockStatusWriter).Times(2)
//mockStatusWriter.EXPECT().Patch(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(2)
expectNoStatusPatch(ctrl)

scaler1.EXPECT().GetMetricSpecForScaling(gomock.Any()).Return(metricsSpecs1)
scaler2.EXPECT().GetMetricSpecForScaling(gomock.Any()).Return(metricsSpecs2)
scaler1.EXPECT().GetMetricsAndActivity(gomock.Any(), gomock.Any()).Return([]external_metrics.ExternalMetricValue{metricValue1, metricValue2}, true, nil)
Expand All @@ -1023,3 +1017,8 @@ func createMetricSpec(averageValue int64, metricName string) v2.MetricSpec {
},
}
}

func expectNoStatusPatch(ctrl *gomock.Controller) {
statusWriter := mock_client.NewMockStatusWriter(ctrl)
statusWriter.EXPECT().Patch(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
}

0 comments on commit e014c1b

Please sign in to comment.