Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored fallback logic to only patch status when the fallback is e… #5659

Merged
merged 19 commits into from
Aug 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed test failures
Signed-off-by: Bharath Guvvala <bharath.raghavendra@gmail.com>
  • Loading branch information
bharathguvvala committed Jul 15, 2024
commit 44b169b380eb3a6496397f232c0a1285afa64a50
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)
}
Loading