Skip to content

Commit

Permalink
fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SOF3 committed Apr 17, 2023
1 parent dd872dd commit a2fda79
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
9 changes: 4 additions & 5 deletions pkg/controllers/scheduler/framework/plugins/rsp/rsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ func (pl *ClusterCapacityWeight) ReplicaScheduling(

var schedulingWeights map[string]int64
if dynamicSchedulingEnabled {
clusterAvailables := QueryAvailable(clusters, su)
clusterAvailables := QueryAvailable(clusters, su.CurrentUsage)
if len(clusters) != len(clusterAvailables) {
return clusterReplicasList, framework.NewResult(framework.Error)
}

weightLimit, err := CalcWeightLimit(clusters, supplyLimitProportion, su)
weightLimit, err := CalcWeightLimit(clusters, supplyLimitProportion)
if err != nil {
return clusterReplicasList, framework.NewResult(
framework.Error,
Expand Down Expand Up @@ -182,7 +182,6 @@ func (pl *ClusterCapacityWeight) ReplicaScheduling(
func CalcWeightLimit(
clusters []*fedcorev1a1.FederatedCluster,
supplyLimitRatio float64,
su *framework.SchedulingUnit,
) (weightLimit map[string]int64, err error) {
allocatables := QueryAllocatable(clusters)
if len(allocatables) != len(clusters) {
Expand Down Expand Up @@ -272,7 +271,7 @@ func AvailableToPercentage(
}

// QueryAvailable aggregate cluster available resource.
func QueryAvailable(clusters []*fedcorev1a1.FederatedCluster, schedulingUnit *framework.SchedulingUnit) map[string]corev1.ResourceList {
func QueryAvailable(clusters []*fedcorev1a1.FederatedCluster, currentUsage map[string]framework.Resource) map[string]corev1.ResourceList {
ret := make(map[string]corev1.ResourceList)
for _, cluster := range clusters {
available := make(corev1.ResourceList)
Expand All @@ -288,7 +287,7 @@ func QueryAvailable(clusters []*fedcorev1a1.FederatedCluster, schedulingUnit *fr
}
}

usageTmp := schedulingUnit.CurrentUsage[cluster.Name]
usageTmp := currentUsage[cluster.Name]
usage := *usageTmp.Clone()

usage.Add(available)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestAvailableToPercentage(t *testing.T) {
}
makeArgs := func(clusters ...*fedcorev1a1.FederatedCluster) args {
return args{
clusterAvailables: QueryAvailable(clusters),
clusterAvailables: QueryAvailable(clusters, nil),
weightLimit: func() map[string]int64 {
weightLimit, _ := CalcWeightLimit(clusters, 1.0)
return weightLimit
Expand Down
5 changes: 3 additions & 2 deletions pkg/controllers/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package scheduler

import (
"context"
"testing"

"github.com/onsi/gomega"
Expand Down Expand Up @@ -318,7 +319,7 @@ func TestGetSchedulingUnitWithAnnotationOverrides(t *testing.T) {
err = unstructured.SetNestedMap(obj.Object, templateObjectMetaUns, common.TemplatePath...)
g.Expect(err).NotTo(gomega.HaveOccurred())

su, err := scheduler.schedulingUnitForFedObject(obj, test.policy)
su, err := scheduler.schedulingUnitForFedObject(context.Background(), obj, test.policy)
g.Expect(err).NotTo(gomega.HaveOccurred())

// override fields we don't want to test
Expand Down Expand Up @@ -403,7 +404,7 @@ func TestSchedulingMode(t *testing.T) {
g.Expect(err).NotTo(gomega.HaveOccurred())
err = unstructured.SetNestedMap(obj.Object, templateObjectMetaUns, common.TemplatePath...)
g.Expect(err).NotTo(gomega.HaveOccurred())
su, err := scheduler.schedulingUnitForFedObject(obj, test.policy)
su, err := scheduler.schedulingUnitForFedObject(context.Background(), obj, test.policy)
g.Expect(err).NotTo(gomega.HaveOccurred())
g.Expect(su.SchedulingMode).To(gomega.Equal(test.expectedResult))
})
Expand Down

0 comments on commit a2fda79

Please sign in to comment.