Skip to content

Commit

Permalink
[YUNIKORN-2862] Improve nodesorting test coverage (#967)
Browse files Browse the repository at this point in the history
Closes: #967

Signed-off-by: Craig Condit <[email protected]>
  • Loading branch information
SP12893678 authored and craigcondit committed Sep 9, 2024
1 parent 6f06490 commit 7c51e82
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
4 changes: 0 additions & 4 deletions pkg/scheduler/objects/nodesorting.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ func NewNodeSortingPolicy(policyType string, resourceWeights map[string]float64)
sp = fairnessNodeSortingPolicy{
resourceWeights: weights,
}
default:
sp = fairnessNodeSortingPolicy{
resourceWeights: weights,
}
}

log.Log(log.SchedNode).Debug("new node sorting policy added",
Expand Down
46 changes: 43 additions & 3 deletions pkg/scheduler/objects/nodesorting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,20 @@ partitions:
if !ok {
t.Fatal("Didn't get expected policy")
}
resourceWeights := policy.ResourceWeights()
assert.Equal(t, 2, len(resourceWeights), "Wrong size of resourceWeights")
assert.Equal(t, resourceWeights["vcore"], 1.0, "Wrong weight for vcore")
assert.Equal(t, resourceWeights["memory"], 1.0, "Wrong weight for memory")

assert.Equal(t, 2, len(policy.resourceWeights), "Wrong size of resourceWeights")
assert.Equal(t, policy.resourceWeights["vcore"], 1.0, "Wrong weight for vcore")
assert.Equal(t, policy.resourceWeights["memory"], 1.0, "Wrong weight for memory")
// case: bin packing policy
binPackingPolicy, ok := NewNodeSortingPolicy("binpacking", weights).(binPackingNodeSortingPolicy)
if !ok {
t.Fatal("Didn't get expected policy")
}
resourceWeights = binPackingPolicy.ResourceWeights()
assert.Equal(t, 2, len(resourceWeights), "Wrong size of resourceWeights")
assert.Equal(t, resourceWeights["vcore"], 1.0, "Wrong weight for vcore")
assert.Equal(t, resourceWeights["memory"], 1.0, "Wrong weight for memory")
}

func TestInvalidResourceWeightsFromConfig(t *testing.T) {
Expand Down Expand Up @@ -287,3 +297,33 @@ func TestSortPolicy(t *testing.T) {
assert.Equal(t, node1.NodeID, nodes[0].NodeID, "wrong initial node (fair, node2 half-filled)")
assert.Equal(t, node2.NodeID, nodes[1].NodeID, "wrong second node (binpacking, node2 half-filled")
}

func TestAbsResourceUsage(t *testing.T) {
// case: zero weight & NaN shares
nc := NewNodeCollection("test")
weights := map[string]float64{
"vcore": 4.0,
"memory": 0,
}
fair, ok := NewNodeSortingPolicy("fair", weights).(fairnessNodeSortingPolicy)
if !ok {
t.Fatal("Didn't get fair policy")
}

nc.SetNodeSortingPolicy(fair)
totalRes := resources.NewResourceFromMap(map[string]resources.Quantity{"vcore": 0, "memory": 16000})

proto1 := newProto("test1", totalRes, nil, map[string]string{})
node1 := NewNode(proto1)
if err := nc.AddNode(node1); err != nil {
t.Fatal("Failed to add node1")
}

// add allocations
res1 := resources.NewResourceFromMap(map[string]resources.Quantity{"vcore": 0, "memory": 12000})
alloc1 := newAllocation("test-app-1", "test1", res1)
node1.AddAllocation(alloc1)

// node1 w/ fair: 400% vcore, 0% memory => ((0 * 4) + (.75 * NaN)) / 0 = 0
assert.Equal(t, 0.0, fair.ScoreNode(node1), "Wrong fair score for node1")
}

0 comments on commit 7c51e82

Please sign in to comment.